Showing posts with label System Admin. Show all posts
Showing posts with label System Admin. Show all posts

Thursday, December 29, 2016

Copy Files via SSH from Another Server FTP

Recently for one of my project our server was hacked and some files were deleted and corrupted with malwares. So we had to restore the old backups. We were using the contabo web server where we have separate backup server with 100 GB space which was accessible only through FTP from the SSH. So in this blog I am going to explain how you can copy files Copy Files via SSH from Another Server FTP.

Step 1: Login to SSH with your SSH username and password. 


ssh yourusername@host

On prompt of password enter password and login.



Step 2 : Go to directory where you want to copy files from FTP.


cd /yourpath/to/folder

Step 3: Connect to FTP


Use following command to connect to FTP

ftp hostname

It will ask for username and password. Once you enter correct username and password, you will get ftp command prompt.



Step 4 : Go to directory from where you want to copy files on FTP.


cd /yourpath/to/folder

You can use cd command on FTP just like you  use on SSH.

Step 5 : Copy Specific File.

Use following command to copy file.

get filename

And wait for the process to be finished.

Step 6 : Exit From FTP


Use following command to close FTP and return back to SSH.

bye

With this you will close the FTP session and you are back to SSH session and you can see the copied files using LS command.

Wednesday, September 23, 2015

Upload File From Local Machine to Remote Server with SSH

Hello,

Recently while working on SSL on my Amazon EC 2 server I had to upload few certificates files from my local machine to EC 2 server. I had to spent some time to figure out this so thought of publishing blog on it so this may help others

First lets see how to upload file to remote server with permission on directory. We will use scp command for it. Following is the syntax.

$ scp /path/to/local/file sshuser@host:/path/to/remote/server

Once you run command it will prompt you for password. When you enter password it will upload file.

Now lets see what if you don't have password and have public or private key. Following is the command.

$ scp -i "yourkey" /path/to/local/file sshuser@host:/path/to/remote/server

If you have specified correct key it will upload your file.

Now here comes the real problem with EC 2. I was trying to upload crt file to system directory which was not allowed. So what you have to do is upload that file default ssh directory with following command

$ scp -i "yourkey" /path/to/local/file sshuser@host:filename

And then go to that directory. Usually in amazon EC 2. It's /home/ubntu directory. Then you can copy files from here using cp command with sudo.

I hope this helps you and dave your time.




Monday, August 31, 2015

Install and Configure PHP/Apache on Amazon EC 2 with Ubuntu (With SFTP)

Hello,

Recently for one of my project we moved our web application to Amazon EC 2. So we had to configure Aapche and setup SFTP there. I faced some difficulties in setting this up so here in blog I am going to explain you the process so it will help you.

First of all login to SSH on your Amazon EC 2 instance. For that first you have to download public key from your amazon EC 2 instance.  You can use public IP of your EC 2 instance to login to SSH.

Open your terminal and type following command.

ssh -i "YourKey.pem" ubuntu@your_ip_address

once you are logged in first of we have to install apache. For that run following command.

First we will install apache with PHP 7 and configure it.

sudo apt-get install apache2 php7.0 libapache2-mod-php7.0
Now verify it


a2query -m php7.0
Load PHP module.


sudo a2enmod php7.0

Restart apache.


sudo service apache2 restart

New version of ubuntu comes with PHP 7 but to access it you have to install php command lines. Run following command.


sudo apt-get install php7.0-cli

Now test it with

php -v

This will install apache, php with single command. Once installation is done type public ip in browser and it should show apache startup page. If you see this page that means apache installed. Now lets test PHP.

Go to your apache root directory with following command

cd /var/www/html

There will be one index.html file. We have to remove this and create new file for testing.

sudo rm index.html

sudo vim index.php

This will open vim editor, press i and now you can type in file. Let's create simple php file

<?php
     echo "Hello AWS";
?>


press esc and : and type wq this will save file. Now again type public IP in browser and it should show Hello AWS on browser.

Now let's create new SFTP user. But for that first we have to allow password authentication for SSH. Type following command.

cd /etc/ssh
sudo vim sshd_config

Find allowPasswordAuthetnciation. It will be set as no, make it yes and save the file and restart SSH service.


sudo service ssh restart

Now we can add user with password.

sudo adduser --home /var/www/html username

It will ask for password. Now user is created with same group name. Now we have to make this user, owner of /var/www/html so we can edit files via FileZilla. Now lets fist change ownership of folders and files.

sudo chown -R root:username /var/www/html
sudo find /var/www/html -type f -exec chmod 664 {} \;
sudo find /var/www/html -type d -exec chmod 775 {} \;
sudo find /var/www/html -type d -exec chmod g+s {} \;

That's it now you can use this username and password with SFTP in FileZilla. Hope this helps you.