linux – chrooting用户在使用sftp时会导致“连接已关闭”消息

首先,我是一个 linux新手,所以请不要假设太多知识.我正在使用CentOS 5.8(最终版)并使用OpenSSH版本5.8p1.

我做了一个用户playwithbits,我试图chroot到目录home / nginx / domains / playwithbits / public

我在sshd_config文件中使用以下匹配语句:

Match group web-root-locked
         ChrootDirectory /home/nginx/domains/%u/public
         X11Forwarding no
         AllowTcpForwarding no
         ForceCommand /usr/libexec/openssh/sftp-server

#id playwithbits返回:uid = 504(playwithbits)gid = 504(playwithbits)groups = 504(playwithbits),507(web-root-locked)

我已将用户的主目录更改为:home / nginx / domains / playwithbits / public

现在,当我尝试使用此用户时,我立即收到消息:连接已关闭

有谁知道我做错了什么?

编辑:根据@Dennis Williamson的建议我已经在调试模式下连接(我认为……如果我错了,请纠正我).

通过使用chmod将所有文件的递归权限直接设置为700,我取得了一些进展.现在,当我尝试登录时仍然收到以下消息(仍然连接被拒绝):

Connection from [My ip address] port 38737
debug1: Client protocol version 2.0; client software version OpenSSH_5.6
debug1: match: OpenSSH_5.6 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8
debug1: permanently_set_uid: 74/74
debug1: list_hostkey_types: ssh-rsa,ssh-dss
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received
debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: KEX done
debug1: userauth-request for user playwithbits service ssh-connection method none
debug1: attempt 0 failures 0
debug1: user playwithbits matched group list web-root-locked at line 91
debug1: PAM: initializing for "playwithbits"
debug1: PAM: setting PAM_RHOST to [My host info]
debug1: PAM: setting PAM_TTY to "ssh"
debug1: userauth-request for user playwithbits service ssh-connection method password
debug1: attempt 1 failures 0
debug1: PAM: password authentication accepted for playwithbits
debug1: do_pam_account: called
Accepted password for playwithbits from [My ip address] port 38737 ssh2
debug1: monitor_child_preauth: playwithbits has been authenticated by privileged process
debug1: SELinux support disabled
debug1: PAM: establishing credentials
User child is on pid 3942
debug1: PAM: establishing credentials
Changed root directory to "/home/nginx/domains/playwithbits/public"
debug1: permanently_set_uid: 504/504
debug1: Entering interactive session for SSH2.
debug1: server_init_dispatch_20
debug1: server_input_channel_open: ctype session rchan 0 win 2097152 max 32768
debug1: input_session_request
debug1: channel 0: new [server-session]
debug1: session_new: session 0
debug1: session_open: channel 0
debug1: session_open: session 0: link with channel 0
debug1: server_input_channel_open: confirm session
debug1: server_input_global_request: rtype no-more-sessions@openssh.com want_reply 0
debug1: server_input_channel_req: channel 0 request env reply 0
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req env
debug1: server_input_channel_req: channel 0 request subsystem reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req subsystem
subsystem request for sftp by user playwithbits
debug1: subsystem: cannot stat /usr/libexec/openssh/sftp-server: Permission denied
debug1: subsystem: exec() /usr/libexec/openssh/sftp-server
debug1: Forced command (config) '/usr/libexec/openssh/sftp-server'
debug1: session_new: session 0
debug1: Received SIGCHLD.
debug1: session_by_pid: pid 3943
debug1: session_exit_message: session 0 channel 0 pid 3943
debug1: session_exit_message: release channel 0
debug1: session_by_channel: session 0 channel 0
debug1: session_close_by_channel: channel 0 child 0
debug1: session_close: session 0 pid 0
debug1: channel 0: free: server-session,nchannels 1
Received disconnect from [My ip address]: 11: disconnected by user
debug1: do_cleanup
debug1: do_cleanup
debug1: PAM: cleanup
debug1: PAM: closing session
debug1: PAM: deleting credentials

解决方法

从服务器端调试时,这些问题总是更容易.我建议在调试模式下启动第二台服务器,例如/usr/sbin / sshd -p 2222 -d.然后,您可以使用sftp -P 2222 user @ remotehost从您的客户端连接,并期望服务器告诉您它为什么断开连接.很可能存在权限问题,我的猜测是您不满足主目录由root拥有的要求.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


查找全部容器的日志文件 $ sudo find /var/lib/docker/containers -name *.log 查看日志位置 $ docker inspect --format='{{.LogPath}}' <container_name> 实时查询内容 $
Linux日志文件中列属性的详细解析
在Linux系统中没有duf命令,如何有效地管理磁盘空间?
深入探讨EncryptPad在Linux操作系统中的功能和优势
原理和应用场景:Linux中ttyload工具的工作原理和实际用途
深度解析SELinux的三种策略类型
评估Linux系统性能的ttyload工具使用效果
分享在Linux系统中检测SSH版本的方法
介绍Linux平台上的数据加密工具EncryptPad
在Linux系统中,如何查看和诊断块设备信息?
在Linux环境下如何查看块设备信息?
探索Linux操作系统下的数据加密工具EncryptPad
学会在Linux系统中查看硬盘信息
分析SELinux:原理与实践
掌握SELinux策略类别
技巧:有效解读和管理Linux日志文件
查看Linux系统中的所有用户
了解Linux系统中各种不同类型的日志文件
深入理解Linux PS命令
方法:在Linux操作系统中查看用户