SFTP将用户登录限制在某一个目录

sftp将W用户登录限制在/file/w目录

(1)添加用户并且设置密码
useradd -d /w -s /bin/false W
passwd W

(2)修改/etc/ssh/sshd_config文件
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp

Match User W
ChrootDirectory /file/
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

(3)修改权限并且检查
chmod -R 755 /file/w
chown root:root /file
ll -ld /file/w/
drwxr-xr-x. 3 root root 21 Aug 8 09:51 /file/w/

(4)重新启动sshd服务
systemctl restart sshd

(5)在本地进行测试
sftp W@localhost
W@localhost's password:
Connected to localhost.
sftp> pwd
Remote working directory: /w
sftp> cd ..
sftp> pwd
Remote working directory: /
sftp> exit

注意:在clinet登录后, 提示没有权限, 请检查server端是否开了selinux, 如果开启selinux, 可以将其关闭后, 再次重启sshd服务

猜你喜欢

转载自blog.51cto.com/13625527/2156452
今日推荐