In my previous post, i discussed about how to install & configureFTP Server on Ubuntu. In this post, i will discuss about how to setup SFTP server in Ubuntu. First you need to install openssh-server, which can be done using command:
1
sudo apt-get install openssh-server ssh
You can use the following commands for ssh:
1
sudo service ssh start # Starts SSH Servier
2
sudo service ssh restart # Restarts SSH Server
3
sudo service ssh stop # Stops SSH Server
4
sudo service ssh status # Gives a short description of the status of the SSH server
First create a backup of the/etc/ssh/sshd_configfile and name it as/etc/ssh/sshd_config.bak. When done, open the/etc/ssh/sshd_configfile:
执行如下命令:sudo usermod -a -G sftpusers test
再sshd_config中加入如下内容:
Match user test
ChrootDirectory /home/test
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp
为了不让test账户登录,可以设置/etc/passwd中的test账户为nologin。
Now lets create the relevant users & groups. First the create user groupsftpusersusing command:
1
sudo groupadd sftpusers
Now create a user supposesftpuser.The commands listed below will create the user, add it to thesftpusers, and update its password
1
sudo adduser sftpuser
2
sudo usermod -a -G sftpusers sftpuser
3
sudo passwd sftpuser
Now proceed with modifying the permissions of the users home directory to allow for chrooting:
1
sudo chownroot:sftpusers /home/sftpuser
2
sudo chmod750 /home/sftpuser
Create a directory in whichsftpuseris free to put any files in it: