导读 | 你的openssh-server版本至少得失4.8p1, 因为配置权限需要版本添加的新配置项ChrootDirectory来完成。如何查看自己服务器上的ssh版本?大家可以尝试以下命令:$ ssh -V |
具体实施步骤:
$ groupadd sftpusers
$ useradd -s /bin/false -G sftpuser test
注意这里我们将test用户的shell设置为/bin/false使他没有登陆shell的权限
找到Subsystem这个配置项,将其修改为
Subsystem sftp internal-sftp
然后再到文件最尾处增加配置设定属于用户组sftpusers的用户都只能访问他们自己的home文件夹
Match Group sftpusers ChrootDirectory %h ForceCommand internal-sftp AllowTcpForwarding no
保存并关闭文件
chown root ~test
$ service sshd restart
$ ssh test@localhost
连接会被拒绝或者无法登陆
$ sftp tesst@localhost
登陆后你会发现你的账号无法切换到除自己home目录之外的地方的
常见问题:
如果你链接服务器的时候出现下面的提示:
Write failed: Broken pipe Couldn't read packet: Connection reset by peer
这个问题的原因是ChrootDirectory的权限问题,你设定的目录必须是root用户所有,否则就会出现问题。所以请确保sftp用户根目录的所有人是root, 权限是 750 或者 755。
原文来自:http://www.jsgho.net/help/fwq/30399.html
本文地址: https://www.linuxprobe.com/linux-sftp.html编辑:郝大发,审核员:逄增宝
本文原创地址:https://www.linuxprobe.com/linux-sftp.html编辑:public,审核员:暂无