Setting Up SFTP Server on Ubuntu

02/12/2020


Install openssl-server and openssl-sftp-server via package manager.

Create a user group (“sftpg” for example) for SFTP users.

sudo groupadd sftpg

Create a user (“tester”) and add it to the new group.

sudo useradd -g sftpg tester
sudo passwd tester

Create a folder and set file permissions for user download.

Note: The owner and owner group for /sftp/ must be “root” while the same fields for /sftp/tester/ must be set as “root” and “sftpg” respectively.

sudo mkdir /sftp
sudo mkdir /sftp/tester
sudo chown -R root:sftpg /sftp/tester
sudo chmod 755 /sftp
sudo chmod 755 /sftp/tester

Also create a folder for upload:

sudo mkdir /sftp/tester/upload
sudo chown -R tester:sftpg /sftp/tester/upload

Edit /etc/ssh/sshd.config and append the following lines:

Match Group sftpg
    ChrootDirectory /sftp/%u
    ForceCommand internal-sftp

Restart ssh server:

sudo systemctl restart sshd
Back to Top

SYANG.IO © 2021