当我尝试连接到某个服务器(位于~/.ssh/known_hosts
)时,我已将公钥复制到该服务器,它总是询问我的密码。如果我关闭连接并重试,它会正确使用我的密钥。如果我在一两个小时后再次尝试连接,它会再次询问我的密码。
第一个连接:
aurelien ~ > ssh -v fac
OpenSSH_5.9p1, OpenSSL 1.0.0e 6 Sep 2011
debug1: Reading configuration data /home/aurelien/.ssh/config
debug1: /home/aurelien/.ssh/config line 27: Applying options for fac
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to zzzzzzzz.univ-lyon1.fr [a.b.c.d] port 22.
debug1: Connection established.
debug1: identity file /home/aurelien/.ssh/id_rsa type 1
debug1: identity file /home/aurelien/.ssh/id_rsa-cert type -1
debug1: identity file /home/aurelien/.ssh/id_dsa type -1
debug1: identity file /home/aurelien/.ssh/id_dsa-cert type -1
debug1: identity file /home/aurelien/.ssh/id_ecdsa type -1
debug1: identity file /home/aurelien/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5
debug1: match: OpenSSH_5.1p1 Debian-5 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 49:bb:84:f5:0b:7c:e3:be:29:9d:7b:09:1b:a0:4e:f4
debug1: Host 'zzzzzzzz.univ-lyon1.fr' is known and matches the RSA host key.
debug1: Found key in /home/aurelien/.ssh/known_hosts:21
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: /home/aurelien/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/aurelien/.ssh/id_dsa
debug1: Trying private key: /home/aurelien/.ssh/id_ecdsa
debug1: Next authentication method: password
[email protected]'s password:
debug1: Authentication succeeded (password).
Authenticated to zzzzzzzz.univ-lyon1.fr ([a.b.c.d]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Fri Dec 16 20:53:27 2011 from xxxxxx.rev.numericable.fr
fac ~ $ logout
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
logout
logout
debug1: channel 0: free: client-session, nchannels 1
Connection to zzzzzzzz.univ-lyon1.fr closed.
Transferred: sent 2576, received 2216 bytes, in 13.5 seconds
Bytes per second: sent 190.8, received 164.1
debug1: Exit status 0
第二次连接(紧接着第一次连接):
aurelien ~ > ssh -v fac
OpenSSH_5.9p1, OpenSSL 1.0.0e 6 Sep 2011
debug1: Reading configuration data /home/aurelien/.ssh/config
debug1: /home/aurelien/.ssh/config line 27: Applying options for fac
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to zzzzzzzz.univ-lyon1.fr [a.b.c.d] port 22.
debug1: Connection established.
debug1: identity file /home/aurelien/.ssh/id_rsa type 1
debug1: identity file /home/aurelien/.ssh/id_rsa-cert type -1
debug1: identity file /home/aurelien/.ssh/id_dsa type -1
debug1: identity file /home/aurelien/.ssh/id_dsa-cert type -1
debug1: identity file /home/aurelien/.ssh/id_ecdsa type -1
debug1: identity file /home/aurelien/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5
debug1: match: OpenSSH_5.1p1 Debian-5 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 49:bb:84:f5:0b:7c:e3:be:29:9d:7b:09:1b:a0:4e:f4
debug1: Host 'zzzzzzzz.univ-lyon1.fr' is known and matches the RSA host key.
debug1: Found key in /home/aurelien/.ssh/known_hosts:21
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: /home/aurelien/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to zzzzzzzz.univ-lyon1.fr ([a.b.c.d]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Tue Dec 20 14:17:17 2011 from xxxxxx.rev.numericable.fr
fac ~ $ logout
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
-bash: /home/etu/a/yyyyyyy/.bash_logout: Permission denied
logout
debug1: channel 0: free: client-session, nchannels 1
Connection to zzzzzzzz.univ-lyon1.fr closed.
Transferred: sent 3360, received 2648 bytes, in 748.5 seconds
Bytes per second: sent 4.5, received 3.5
debug1: Exit status 0
编辑:我的私钥未加密(没有密码),在其他服务器上没有遇到此问题。我在 Linux 机器上,安装了 awesomewm,没有使用任何代理(我猜除了 ssh-agent 之外?)。
答案1
我以前在连接到具有 AFP 主目录的 Mac 时见过这种情况。您的 authorized_keys 文件位于自动挂载的主目录中,该目录要么需要身份验证才能访问,要么挂载时间太长。
您要么需要修复您的 NFS 自动挂载系统,要么停止使用用户验证的文件共享系统作为主目录,要么设置 sshd 在本地目录中查找您的 authorized_keys。
以下是使用最后一个选项解决该问题的方法:
在本地磁盘上任意位置设置一个目录来存储authorized_keys文件。
/var/local/ssh
可能是合适的。为每个需要使用密钥登录的用户创建一个目录。使其归相应用户所有,且其他任何人都无法读取。
将以下行添加到系统范围
sshd_config
文件中:AuthorizedKeysFile /var/local/ssh/%u/authorized_keys
重新启动 sshd。
答案2
可能的原因是您的远程主目录是在登录时挂载的。因此,还没有~/.ssh/authorized_keys
文件需要使用您的密钥进行身份验证。在第二次登录时,您的主目录仍处于挂载状态,并且基于密钥的身份验证有效。这意味着您的主目录在您注销一段时间后被卸载。
只是猜测,但它在这里的系统上就是这样工作的。