首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SFTP Chroot Ubuntu 10.10

SFTP Chroot Ubuntu 10.10
EN

Server Fault用户
提问于 2014-02-27 12:58:18
回答 2查看 359关注 0票数 1

我试图让一个SFTP只访问他的主目录给用户。

这是用户的/etc/passwd行:

代码语言:javascript
复制
bob:x:1003:1003::/home/bob:/bin/false

我编辑了/etc/ssh/sshd_config文件如下:

代码语言:javascript
复制
#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添加到他的家中,并将其添加到正确的位置:

代码语言:javascript
复制
Match user bob
            ChrootDirectory /home/bob
            AllowTcpForwarding no
            X11Forwarding no
            ForceCommand internal-sftp

我更改了对鲍勃家的许可:

代码语言:javascript
复制
drwxr-xr-x  3 root    root      4096 2014-02-27 13:13 bob

现在,当我尝试sftp bob@myserver.com时,答案是:

代码语言:javascript
复制
Write failed: Broken pipe
Connection closed

我的OpenSSH版本是1:5.5p1-4 ubuntu6

我哪里错了??我能在哪里解决我的问题?

编辑:经过一些调试之后,我发现了以下错误消息:

代码语言:javascript
复制
bad ownership or modes for chroot directory component "/"
EN

回答 2

Server Fault用户

发布于 2014-02-27 13:05:06

我认为您只需指定ChrootDirectory /home,它将自动替代/home/bob。否则,它正在调查/home/bob/bob

编辑:还请确保chroot目录为root所有,不属于组可写。如果您需要一个可写目录,那么您需要创建一个子文件夹。

代码语言:javascript
复制
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
票数 1
EN

Server Fault用户

发布于 2014-02-27 14:05:52

man sshd_config

代码语言:javascript
复制
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是根用户拥有的,其他用户不能写

代码语言:javascript
复制
Match user pippo
        ChrootDirectory /home
        AllowTcpForwarding no
        X11Forwarding no
        ForceCommand internal-sftp

在这种情况下,这是行不通的,因为ChrootDirectory /home/pippo不是根用户拥有的,其他用户可以写

代码语言:javascript
复制
Match user pippo
        ChrootDirectory /home/pippo
        AllowTcpForwarding no
        X11Forwarding no
        ForceCommand internal-sftp
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/578724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档