无密码 SSH 仅在调试模式下工作
Posted
技术标签:
【中文标题】无密码 SSH 仅在调试模式下工作【英文标题】:Passwordless SSH works only in debug mode 【发布时间】:2015-05-19 06:42:47 【问题描述】:我有两台机器,用户相同,需要在它们之间做无密码ssh,我有两个用户medya和orainst
medya home 是 /home/medya/ orainst 主页是 /tools/appsw/oracle/orainst
我已经为他们两个设置了无密码(是的,我发誓我做了所有的权限,虔诚地)。
它适用于普通主目录 (medya) 中的任何用户,但不适用于 orainst。
最奇怪的是,如果我在调试模式下运行 ssh 服务器,它对两个用户都可以正常工作!!!
这里是 ssh 作为服务启动和 ssh 作为调试启动的日志
这是失败的地方:
debug1: trying public key file /tools/appsw/oracle/orainst/.ssh/authorized_keys
debug1: Could not open authorized keys '/tools/appsw/oracle/orainst/.ssh/authorized_keys': Permission denied
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 500/500 (e=0/0)
debug1: trying public key file /tools/appsw/oracle/orainst/.ssh/authorized_keys
这是完整的日志:
[root@ip-10-16-4-114 oracle]# service sshd start
Starting sshd: debug1: sshd version OpenSSH_5.3p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 3, 3
Connection from 10.16.4.113 port 56175
debug1: Client protocol version 2.0; client 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.3
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 orainst service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "orainst"
debug1: PAM: setting PAM_RHOST to "10.16.4.113"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: userauth-request for user orainst service ssh-connection method publickey
debug1: attempt 1 failures 0
debug1: temporarily_use_uid: 500/500 (e=0/0)
**debug1: trying public key file /tools/appsw/oracle/orainst/.ssh/authorized_keys
debug1: Could not open authorized keys '/tools/appsw/oracle/orainst/.ssh/authorized_keys': Permission denied
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 500/500 (e=0/0)
debug1: trying public key file /tools/appsw/oracle/orainst/.ssh/authorized_keys**
debug1: Could not open authorized keys '/tools/appsw/oracle/orainst/.ssh/authorized_keys': Permission denied
debug1: restore_uid: 0/0
Failed publickey for orainst from 10.16.4.113 port 56175 ssh2
Connection closed by 10.16.4.113
debug1: do_cleanup
debug1: do_cleanup
debug1: PAM: cleanup
并记录以调试模式运行 ssh 服务器(当我这样做时,两个用户都可以进行无密码 ssh)
[root@ip-10-16-4-114 oracle]# /usr/sbin/sshd -d -p 2222
debug1: sshd version OpenSSH_5.3p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: rexec_argv[2]='-p'
debug1: rexec_argv[3]='2222'
Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 2222 on 0.0.0.0.
Server listening on 0.0.0.0 port 2222.
debug1: Bind to port 2222 on ::.
Server listening on :: port 2222.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 3, 3
Connection from 10.16.4.113 port 47631
debug1: Client protocol version 2.0; client 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.3
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 orainst service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "orainst"
debug1: PAM: setting PAM_RHOST to "10.16.4.113"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: userauth-request for user orainst service ssh-connection method publickey
debug1: attempt 1 failures 0
debug1: temporarily_use_uid: 500/500 (e=0/0)
debug1: trying public key file /tools/appsw/oracle/orainst/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: matching key found: file /tools/appsw/oracle/orainst/.ssh/authorized_keys, line 1
Found matching RSA key: 6c:ab:f3:3b:68:c3:ed:f1:d6:ae:a5:f8:06:2f:d3:8c
debug1: restore_uid: 0/0
debug1: ssh_rsa_verify: signature correct
debug1: do_pam_account: called
Accepted publickey for orainst from 10.16.4.113 port 47631 ssh2
debug1: monitor_child_preauth: orainst has been authenticated by privileged process
debug1: temporarily_use_uid: 500/500 (e=0/0)
debug1: ssh_gssapi_storecreds: Not a GSSAPI mechanism
debug1: restore_uid: 0/0
debug1: SELinux support enabled
debug1: PAM: establishing credentials
debug1: temporarily_use_uid: 500/500 (e=0/0)
debug1: ssh_gssapi_storecreds: Not a GSSAPI mechanism
debug1: restore_uid: 0/0
User child is on pid 6171
debug1: PAM: establishing credentials
debug1: permanently_set_uid: 500/500
debug1: Entering interactive session for SSH2.
debug1: server_init_dispatch_20
debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384
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 pty-req reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req pty-req
debug1: Allocating pty.
debug1: session_new: session 0
debug1: session_pty_req: session 0 alloc /dev/pts/1
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 shell reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req shell
【问题讨论】:
orainst 用户的默认 shell 是什么? @ElliottFrisch 我相信他们是一样的。 (我怎样才能仔细检查?) 我投票结束这个问题,因为它属于serverfault.com 查看 /etc/passwd 中的 GECOS 字段 @ElliottFrisch 都使用 /bin/bash 和orainst:x:500:500::/tools/appsw/oracle/orainst:/bin/bash
【参考方案1】:
我认为真正的问题是 .ssh 文件夹路径中存在符号链接会触发权限检查。与 SELinux 要求 authorized_keys 文件禁止对该文件的组写访问(本质上具有 600 的 chmod 值)类似,它对 .ssh 文件夹和到 authorized_keys 文件的路径中的任何符号链接强制执行相同的规则。
这里的答案我觉得不错:https://unix.stackexchange.com/questions/152417/why-cant-i-use-public-private-key-authentication-with-ssh-on-arch-linux
【讨论】:
【参考方案2】:我也遇到了这个问题,用下面的方法解决了:
restorecon .ssh/
restorecon .ssh/authorized_keys
这里的其他答案提示我这是一个 SELinux 问题,将默认上下文恢复到文件夹及其内容解决了这个问题。
【讨论】:
【参考方案3】:我用这个解决了这个问题
echo 0 > /selinux/enforce
原来 selinux 不喜欢我用户的主文件夹是符号链接。
【讨论】:
【参考方案4】:同样的事情发生在我身上,但我在 Windows 中运行 OpenSSH。由于这个线程中的答案,我意识到原因可能是对 authorized_keys 文件的权限。登录在调试模式下工作,因为该模式使用对文件具有权限的同一用户运行,但 OpenSSH 服务使用 LocalSystem 用户运行。授予该用户对 authorized_keys 的权限解决了这个问题。
【讨论】:
以上是关于无密码 SSH 仅在调试模式下工作的主要内容,如果未能解决你的问题,请参考以下文章
OpenGL 程序仅在 Visual Studio 2013 中的调试模式下工作
父 NSManagedObjectContext 在子保存后没有变化,但仅在发布模式下(在调试模式下工作)