November 18, 2020 / Nirav Shah
SFTP (SSH File Transfer Protocol, also known as Secure FTP) is a popular method for securely transfer of files to/from remote systems. SFTP was designed as an extension of the Secure Shell protocol (SSH) version 2.0 to enhance secure file transfer capabilities.
Per-requisites
Step 1
Step 2
Connect to your server
Step 3
Update and upgrade your server to get the latest packages
$ sudo apt update && sudo apt upgrade -y
Step 4
Install apache2 as we are going to give access to SFTP of HTML folder only
$ sudo apt install apache2 -y
Step 5
Now add a new user ( In our case, we have given name sftptestuser )
$ sudo adduser sftptestuser
Create a password to access the user via FTP/sFTP client
Optional Fill all the details and the press y and press ENTER
Step 6
Add the file path in front of the username by editing in /etc/passwd file
$ sudo vim /etc/passwd
As you can see in the last line
Step 7
Edit the /etc/ssh/sshd_config to allow the access the user via password
$ sudo vim /etc/ssh/sshd_config
Add the below line to the end of the config file as you can see in the image
$ Match User
$ PasswordAuthentication yes
Step 8
Navigate to the /var/www
$ cd /var/www
Step 9
Change the ownership of the HTML to be accessible to the sFTP user
$ sudo chown -R ftpusername:www-data html
Step 10
Go inside the HTML folder and paste the command as under
$ cd /var/www/html
$ sudo find . -type d -exec chmod -R 775 {} \;
$ sudo find . -type f -exec chmod -R 664 {} \;
Step 11
Go to /var/www and paste the command this will change the ownership of every file that is in the folder HTML
$ cd /var/www
$ sudo chmod -R ugo+s html
Step 12
Now restart the sshd service to implement the changes we have done
$ sudo service sshd restart
Step 13
As you can see in all the above steps we have configured the sFTP user now we will try to connect to the user via FTP/SFTP
As you can see /var/www/html is listed in the image
Also Read : Install Hibernation for Ubuntu 16.04 LTS on EC
As a Director of Eternal Web Private Ltd an AWS consulting partner company, Nirav is responsible for its operations. AWS, cloud-computing and digital transformation are some of his favorite topics to talk about. His key focus is to help enterprises adopt technology, to solve their business problem with the right cloud solutions.
Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.