CentOS 6限制用户ssh访问他的主文件夹

CentOS 6限制用户ssh访问他的主文件夹

我正在尝试将新添加的用户限制到他的主目录 /home/username。不希望他能够从中 cd 出来。

我的 sshd_config 如下:

Match User username
       ChrootDirectory %h
       X11Forwarding no
       AllowTcpForwarding no
       ForceCommand internal-sftp

我使用 chown 将 /home/username 目录的所有者设置为 root,并将权限设置为 755。

还将用户添加到 chroot.conf。

重新启动 sshd。但是当我尝试以用户身份登录时,远程服务器关闭了连接。

更新:

SSH 输出(从中编辑了一些信息,例如 IP 地址和 RSA 密钥):

OpenSSH_5.9p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /Users/Mate/.ssh/config
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 (IP address) [IP address] port 22.
debug1: Connection established.
debug1: identity file /Users/Mate/.ssh/id_rsa type 1
debug1: identity file /Users/Mate/.ssh/id_rsa-cert type -1
debug1: identity file /Users/Mate/.ssh/id_dsa type -1
debug1: identity file /Users/Mate/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 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: Some key
debug1: Host 'IP address' is known and matches the RSA host key.
debug1: Found key in /Users/Mate/.ssh/known_hosts:13
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,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/Mate/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive
debug1: Trying private key: /Users/Mate/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
Password:
debug1: Authentication succeeded (keyboard-interactive).
Authenticated to IP address ([IP address]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_CTYPE = UTF-8
debug1: channel 0: free: client-session, nchannels 1
Connection to IP address closed by remote host.
Connection to IP address closed.
Transferred: sent 2400, received 2008 bytes, in 0.2 seconds
Bytes per second: sent 10399.6, received 8701.0
debug1: Exit status -1

知道为什么会发生这种情况吗?

答案1

是的。您已强制他仅使用 sftp 协议进行连接ForceCommand internal-sftp。不出所料,这意味着他无法通过 ssh 进入。

相关内容