sftp setup

step 1 : Install OpenSSH package if not installed

sudo apt-get install openssh-server

Step 2 : Create separate group for SFTP users.

sudo addgroup ftpaccess

Step 3 : Edit /etc/ssh/sshd_config file and make changes as below. Find and comment below line.

#Subsystem sftp /usr/lib/openssh/sftp-server

and add these lines to the end of the file.

Subsystem sftp internal-sftp
  Match group ftpaccess
  ChrootDirectory %h
  X11Forwarding no
  AllowTcpForwarding no
  ForceCommand internal-sftp
  PasswordAuthentication yes

Step 4 : Restart sshd service.

sudo service ssh restart

Step 5 : Add user with ftpaccess group and create password.

sudo adduser zql --ingroup ftpaccess --shell /usr/sbin/nologin
sudo passwd zql

Step 6 : Modify home directory permission.

sudo chown root:root /home/zql

Step 7 : Create a directory inside home for upload and modify permission with group.

sudo mkdir /home/zql/shared
sudo chown zql:ftpaccess /home/zql/shared

Step 8: Test ssh login and sftp login

# another host
ssh zql@sftp-host-ip  # this will fail
# another host
sftp zql@sftp-host-ip # input pwd and you will login, but can not access other directory

That's it .

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容