我试图让一个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 bob@myserver.com,一切都很好。
然后,我尝试将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 bob@myserver.com时,答案是:
Write failed: Broken pipe
Connection closed我的OpenSSH版本是1:5.5p1-4 ubuntu6
我哪里错了??我能在哪里解决我的问题?
编辑:经过一些调试之后,我发现了以下错误消息:
bad ownership or modes for chroot directory component "/"发布于 2014-02-27 13:05:06
我认为您只需指定ChrootDirectory /home,它将自动替代/home/bob。否则,它正在调查/home/bob/bob
编辑:还请确保chroot目录为root所有,不属于组可写。如果您需要一个可写目录,那么您需要创建一个子文件夹。
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发布于 2014-02-27 14:05:52
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是根用户拥有的,其他用户不能写
Match user pippo
ChrootDirectory /home
AllowTcpForwarding no
X11Forwarding no
ForceCommand internal-sftp在这种情况下,这是行不通的,因为ChrootDirectory /home/pippo不是根用户拥有的,其他用户可以写
Match user pippo
ChrootDirectory /home/pippo
AllowTcpForwarding no
X11Forwarding no
ForceCommand internal-sftphttps://serverfault.com/questions/578724
复制相似问题