0

我正在尝试为 PCI 合规性设置一些 chrooting。我希望一些用户只能通过 sftp 而不是 ftp 连接(我可以轻松限制)。但是,我需要对 sftp 用户进行 chroot,以便他们可以遍历 dir 树并查看所有内容。

我将此添加到我的 openssh ssd_config 文件中,以首先对一个用户进行测试:

Match User dbl
ChrootDirectory %h
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

当我尝试连接时,我得到这个输出:

$ sftp -v dbl@hostname
OpenSSH_5.9p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug1: Connecting to hostname [x.x.x.x] port 22.
debug1: Connection established.
debug1: identity file /Users/me/.ssh/id_rsa type 1
debug1: identity file /Users/me/.ssh/id_rsa-cert type -1
debug1: identity file /Users/me/.ssh/id_dsa type -1
debug1: identity file /Users/me/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2p2-hpn13v14 FreeBSD-openssh-portable-6.2.p2_2,1
debug1: match: OpenSSH_6.2p2-hpn13v14 FreeBSD-openssh-portable-6.2.p2_2,1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 54:8b:66:39:15:d4:6f:ed:82:d4:c2:82:b0:a3:45:03
debug1: Host 'hostname' is known and matches the RSA host key.
debug1: Found key in /Users/me/.ssh/known_hosts:35
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/me/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/me/.ssh/id_dsa
debug1: Next authentication method: password
dbl@hostname's password:
debug1: Authentication succeeded (password).
Authenticated to hostname ([x.x.x.x]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Connection to hostname closed by remote host.
Transferred: sent 1920, received 2560 bytes, in 0.0 seconds
Bytes per second: sent 1111840.9, received 1482454.5
debug1: Exit status -1
Connection closed

如您所见,在我输入密码后,它立即让我进入,然后立即关闭连接。它甚至没有像应有的那样显示 sftp 提示符。我在这里尝试了其他一些看起来相关但没有得到任何地方的帖子。

每个用户都有 /bin/sh 作为他们的 shell。

4

1 回答 1

0

我已经看到人们过去在使用 SFTP 时遇到过很多类似的问题,而且大多数情况下都是通过在 sshd_config 中添加缺少的第一行来解决的

Subsystem     sftp     internal-sftp
Match Group sftponly
    ChrootDirectory /home/%u
    ForceCommand internal-sftp
    AllowTcpForwarding no

此外,如果您计划添加更多用户,那么设置一个 sftp 组(如下面的配置)可能是明智的。

我放了一篇博文,但它是针对 openssh-5 的。还包含一个肮脏但有效的交互式脚本,可在几秒钟内设置一个新用户。当有新客户加入时,始终使用它来工作。

http://264nmtechblog.wordpress.com/2013/10/

希望这是一些帮助 - 如果不是,可能会发布您的 /var/log/secure 如果您的问题是基于权限的,这可能会给您一个更好的提示。

于 2014-03-15T02:51:13.687 回答