Setup sFTP Server on Ubuntu 20.04

image-1

Install SSH Server

$ sudo apt-get install ssh-server -y
  • Configure FTP on sshd_config

/etc/ssh/sshd_config

$ sudo vi /etc/ssh/sshd_config

Edit sshd_config file

  • find and comment
#Subsystem       sftp    /usr/lib/openssh/sftp-server
  • and append the following to file
Subsystem sftp internal-sftp
Match group ftpaccess
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
  • restart ssh service
$ sudo systemctl restart ssh

Create SFTP user account

  • add group
$ sudo addgroup sftp
  • next, Create user for sFTP
$ sudo useradd -m sftpUser -g sftp

image-1

eg. create user is sftpUser and assign to sftp group

  • then, Set password
$ sudo passwd sftpUser
...
New password:
Retype new password:
passwd: password updated successfully
  • lastly, Change permission for other user on system deny acess
$ sudo chmod 700 /home/sftpUser # /home/<username>

All Done


Test login via SFTP

$ sftp sftpUser@<ip or hostname>

if your has the same problem as below

$ sftpUser@<ip or hostname>: Permission denied (publickey).
Connection closed
Connection closed.
  • change sshd_config

/etc/ssh/sshd_config

PasswordAuthentication no
# to
PasswordAuthentication yes
  • and restart ssh service
$ sudo systemctl restart ssh
  • test login via sFTP again
$ sftp [email protected]
[email protected]'s password:
Connected to xx.xx.xx.xx.
sftp>
  • test connect via FileZilla

image-1