我想给SFTP只能访问他的主目录给用户。
这是用户的/ etc / passwd行:
bob:x:1003:1003::/home/bob:/bin/false
我编辑了/ etc / ssh / sshd_config文件:
#Subsystem sftp /usr/lib/openssh/sftp-server Subsystem sftp internal-sftp # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. UsePAM yes Match user bob AllowTcpForwarding no X11Forwarding no ForceCommand internal-sftp
然后我重新启动ssh: sudo service ssh restart
如果我尝试sftp [email protected]一切正常。
然后我尝试Chroot bob到他家,所以我在正确的地方添加了ChrootDirectory /home/bob :
Match user bob ChrootDirectory /home/bob AllowTcpForwarding no X11Forwarding no ForceCommand internal-sftp
我改变了回家的权限:
drwxr-xr-x 3 root root 4096 2014-02-27 13:13 bob
现在当我尝试sftp [email protected]的答案是:
Write failed: Broken pipe Connection closed
我的OpenSSH版本是1:5.5p1-4ubuntu6
我错在哪里? 我在哪里可以find解决我的问题?
编辑:经过一些debugging,我发现这个错误信息:
bad ownership or modes for chroot directory component "/"
我想你只需要指定ChrootDirectory /home就可以自动replace为/ home / bob。 否则,它正在调查/home/bob/bob
编辑:另外请确保chroot目录由root拥有,不可写入组。 如果你需要有一个可写目录,那么你需要创build一个子文件夹
chown root /home/bob chmod go-w /home/bob mkdir /home/bob/writeable chown bob:sftponly /home/bob/writeable chmod ug+rwX /home/bob/writeable
man sshd_config
Specifies the pathname of a directory to chroot(2) to after authentication. All components of the pathname must be root-owned directories that are not writable by any other user or group.
这是有效的,因为/ home属于root,不能被其他用户写入
Match user pippo ChrootDirectory /home AllowTcpForwarding no X11Forwarding no ForceCommand internal-sftp
在这种情况下,这是行不通的,因为ChrootDirectory / home / pippo不是由root拥有的,并且可被其他用户写入
Match user pippo ChrootDirectory /home/pippo AllowTcpForwarding no X11Forwarding no ForceCommand internal-sftp