0

I have an interesting situation which I'm not even sure where to begin to investigate from. I have a Ubuntu 12.04 server with SSH locked down to PK-auth. When I reboot my server, and try to SSH into it, my PK is not accepted. However, once I login on my server and try to SSH again - the PK is accepted. What is going on here?

SSH Log from Client machine before Server L ogin:

~ 21:45:00

[earth@p2mac:~]$ssh [email protected]
OpenSSH_6.9p1, LibreSSL 2.1.7
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to myhost.me [xxx.xxx.xxx.177] port 22.
debug1: Connection established.
debug1: identity file /Users/earth/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to myhost.me:22 as 'myuser'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:YZCmzxxxxxxxxxxxxxxxxxxxg3w/39A
debug1: Host ‘myhost.me’ is known and matches the ECDSA host key.
debug1: Found key in /Users/earth/.ssh/known_hosts:26
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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/earth/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/earth/.ssh/id_dsa
debug1: Trying private key: /Users/earth/.ssh/id_ecdsa
debug1: Trying private key: /Users/earth/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
[earth@p2mac:~]$

After logging in on the server:

~21:47:00

[earth@p2mac:~]$ssh [email protected] -v
OpenSSH_6.9p1, LibreSSL 2.1.7
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to myhost.me [xx.xx.xxx.177] port 22.
debug1: Connection established.
debug1: identity file /Users/earth/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/earth/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to myhost.me:22 as 'myuser'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:YZCxxxxxxxxxxxxoxxxhFNkCg3w/39A
debug1: Host ‘myhost.me’ is known and matches the ECDSA host key.
debug1: Found key in /Users/earth/.ssh/known_hosts:26
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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/earth/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to myhost.me ([xxx.xxx.xxx.177]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_ALL = POSIX
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-43-generic x86_64)

Full auth log after boot:

Jan 18 21:45:14 myhost sshd[1614]: Server listening on 0.0.0.0 port 22.
Jan 18 21:45:14 myhost sshd[1614]: Server listening on :: port 22.
Jan 18 21:45:15 myhost CRON[1632]: pam_unix(cron:session): session closed for user myuser
Jan 18 21:45:15 myhost CRON[1633]: pam_unix(cron:session): session closed for user myuser
Jan 18 21:45:15 myhost CRON[1634]: pam_unix(cron:session): session closed for user myuser
Jan 18 21:45:29 myhost sshd[2417]: Connection closed by xx.xxx.xxx.177  [preauth]
Jan 18 21:46:55 myhost login[2431]: pam_ecryptfs: Passphrase file wrapped
Jan 18 21:46:57 myhost login[2259]: pam_unix(login:session): session opened for user myuser by LOGIN(uid=0)
Jan 18 21:46:57 myhost systemd-logind[740]: New session c2 of user myuser.
Jan 18 21:47:03 myhost sshd[2514]: Accepted publickey for myuser from xx.xxx.xxx.177  port 62627 ssh2: RSA a3::d7
Jan 18 21:47:03 myhost sshd[2514]: pam_unix(sshd:session): session opened for user myuser by (uid=0)
Jan 18 21:47:03 myhost systemd-logind[740]: New session 1 of user myuser.

*Sorry, I had to delete the previous question in Stack as I accidentally posted some IPs in the logs and then I thought it would be better if I re-posted it here.

3
  • 6
    Are you using encrypted home directories or anything else where some login process is manipulating your home directory?
    – DerfK
    Jan 18, 2016 at 22:15
  • Yes, the home dir encryption is exactly the problem. I have found a solution to this problem which turns out to be actually a bug. As described here: help.ubuntu.com/community/EncryptedHome "SSH public key auth. into your system also will not work, unless you put your public key somewhere outside of your home directory and symbolically link it to your unmounted $HOME/.ssh/authorized_keys. ". The symlink workaround did not work for me, but I think I found another solution as described here (bugs.launchpad.net/ubuntu/+source/openssh/+bug/362427/comments/…) which I am to test.
    – Yavor
    Jan 19, 2016 at 16:48
  • I think you need to be sure that there's a copy of the key in both the encrypted and unencrypted version of the home directory. Also, the ssh server will check to ensure that you are the only user (other than root) that can access that folder/file to prevent people from putting keys into it, so if you put the files somewhere else, that place has to be writable only by your user in a folder that's only writable by your user or root.
    – DerfK
    Jan 19, 2016 at 16:56

0

You must log in to answer this question.

Browse other questions tagged .