How to setup a basic SFTP server in Ubuntu.
Requirements
- No login
- Read and write permissions
- Access only to a base directory
- Default directory should be the base directory
Instalation
Install the sftp server package
sudo apt-get install openssh-server Create sftp group and user
sudo groupadd sftpgroup sudo useradd myuser -m -G sftpgroup -s /usr/sbin/nologin sudo passwd myuser Prepare base sftp directory
sudo chown root:root /home/myuser sudo mkdir /home/myuser/data sudo chown myuser:sftpgroup /home/myuser/data Configure sftp server
Edit the file /etc/ssh/sshd_config
Comment the following line:
#Subsystem sftp /usr/lib/openssh/sftp-server Add the folowing lines at the end of the file:
Subsystem sftp internal-sftp Match group sftpgroup ChrootDirectory %h X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp -d /data Restart the server
sudo service ssh restart Test
$ sftp myuser@localhost myuser@localhost's password: Connected to localhost. sftp> pwd Remote working directory: /data sftp> put test.txt Uploading test.txt to /data/test.txt test.txt 100% 0 0.0KB/s 00:00 sftp> ls test.txt sftp> quit
Top comments (0)