Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When I try to connect to a certain server (present in ~/.ssh/known_hosts) where I copied my public key, it always asks my password. If I close the connection and try again it uses my key correctly. If I try to connect again after a hour or two, it will ask my password again.

1st connection:

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
yyyyyyy@zzzzzzzz.univ-lyon1.fr'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 no-more-sessions@openssh.com
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 eow@openssh.com 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

2nd connection (right after the first one):

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 no-more-sessions@openssh.com
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 eow@openssh.com 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

Edit: My private key is not encrypted (no passphrase) and I don't have this problem on other servers. I'm on a linux box, with awesomewm and I'm not using any agent (apart from ssh-agent I guess?).

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I've seen this before when connecting to a Mac with a AFP home directories. Your authorized_keys file is in an automounted home directory that either requires authentication to access or takes too long to mount.

You either need to fix your NFS automount system, stop using a user authenticated file sharing system for home directories, or set up sshd to look in a local directory for your authorized_keys.

Here is how to solve it with the last option:

  1. Set up a directory to store authorized_keys files on the local disk wherever you want. /var/local/ssh might be appropriate.

  2. Create a directory for each user who should log in with keys. Make them owned by the appropriate user and not readable by anyone else.

  3. Add the following line to your system wide sshd_config file:

    AuthorizedKeysFile /var/local/ssh/%u/authorized_keys
    
  4. Restart sshd.

share|improve this answer
    
I've updated my question. –  Aurélien Dec 20 '11 at 15:24
    
And I have changed my answer. –  Jeff Strunk Dec 20 '11 at 15:45
    
I'm just a user of the system, unfortunately. Thanks anyway! –  Aurélien Dec 20 '11 at 16:01
add comment

A possible reason is that your remote home-directory is mounted at login time. Thus, there is no ~/.ssh/authorized_keys file yet to authenticate against with your key. At the second login, your homedir is still mounted and key-based authentication works. This would imply that your homedir is unmounted after you have logged out for some time.

Just a guess, but it works like this on systems here.

share|improve this answer
    
That's definitely possible... –  Aurélien Dec 20 '11 at 15:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.