Skip to main content

如何在CentOS 7上启用没有Shell访问权限的SFTP

·71 words·1 min
Linux
Rory
Author
Rory
Step by step the ladder is ascended

记录一下在centos搭建SFTP server.

Step 1:创建新用户
#

[root@localhost ~]# adduser guest
[root@localhost ~]# passwd guest

Step 2:为文件传输创建目录
#

[root@localhost ~]# mkdir -p /var/sftp/uploads
[root@localhost ~]# chown root:root /var/sftp    <<< 设置所有者为root
[root@localhost ~]# chmod 755 /var/sftp          <<< 授予同一目录的root写权限,并为其他用户提供只读和执行权限
[root@localhost ~]# chown guest:guest /var/sftp/uploads    <<<将uploads目录的所有权更改为guest

Step 3:限制对一个目录的访问
#

[root@localhost ~]# vi /etc/ssh/sshd_config 
Match User guest
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory /var/sftp
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
[root@localhost ~]# systemctl restart sshd

https://www.digitalocean.com/community/tutorials/how-to-enable-sftp-without-shell-access-on-centos-7