How to setup SFTP server on Ubuntu 18.04 LTS

How to setup SFTP server on Ubuntu 18.04 LTS

Learn How to setup SFTP server on Ubuntu 18.04 LTS.


The below SFTP configuration procedure assumes that you have already configured your FTP server by following our How to setup FTP server on Ubuntu 18.04 LTS guide. Privileged access to your Ubuntu System as root or via sudo command is also required.

Configure SSH Daemon

If you have not done so yet, install SSH server:

$ sudo apt install ssh

Next, In order to configure FTP over OpenSSH server use your favorite text editor to edit existing SSHD configuration file /etc/ssh/sshd_config:

$ sudo nano /etc/ssh/sshd_config

and append the following to the end of the file:

Match group sftp
ChrootDirectory /home
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

The above lines will ensure that users belonging into sftp group will be able to access their home directories, however they will be denied SSH shell access.

edit sshd config

Restart SSH server to apply new changes:

sudo service ssh restart
Create SFTP user account

We are almost done. All that remains is to create a new user account specific to SFTP service. Let’s start by creating a new group called sftp:

$ sudo addgroup sftp
Adding group `sftp' (GID 1001) ...

Next, create a new user eg. sftpuser and assign him to the previously created sftp group:

$ sudo useradd -m sftpuser -g sftp

Set a new password for the sftpuser user:

$ sudo passwd sftpuser 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

Lastly, change access permissions to the user’s home directly to deny access to it to any other users on the same system:

$ sudo chmod 700 /home/sftpuser/

All done.


But if you get any public key error please follow this url :

How to Setup Public Key Authentication on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *