1

I am writing a kickstart install script that will set up a user on a server with the previous files and permissions it held before. The user I am setting up has ssh keys located in .ssh/ that I also copy over so that the authentication is not required to be set up again.

However every time I attempt to ssh to the server the keys are set up for, I am prompted for the password.

It was working after I set up the keys but has stopped working after I created the same user name with the keys that were originally created. I've checked permissions of the files and they are the same in .ssh.

Is this process possible?

Edit to show /var/log/secure on target server

Setting up as new user with ssh keys:

Jul  1 10:24:01 myuser sshd[14957]: Accepted password for targetserveruser from 192.168.55.55 port 33176 ssh2
Jul  1 10:24:02 myuser sshd[14957]: pam_unix(sshd:session): session opened for user targetserveruser by (uid=0)
Jul  1 10:24:02 myuser sshd[14977]: Received disconnect from 192.168.55.55: 11: disconnected by user
Jul  1 10:24:02 myuser sshd[14957]: pam_unix(sshd:session): session closed for user targetserveruser
Jul  1 10:24:21 myuser sshd[14980]: Accepted password for targetserveruser from 192.168.55.55 port 33177 ssh2
Jul  1 10:24:21 myuser sshd[14980]: pam_unix(sshd:session): session opened for user targetserveruser by (uid=0)
Jul  1 10:24:22 myuser sshd[14997]: Received disconnect from 192.168.55.55: 11: disconnected by user
Jul  1 10:24:22 myuser sshd[14980]: pam_unix(sshd:session): session closed for user targetserveruser
Jul  1 10:24:33 myuser sshd[15002]: Connection closed by 192.168.55.55 [preauth]

After repeating key copy process ssh-copy-id (I changed the key shown for security)

Jul  1 10:26:28 myuser sshd[15058]: Accepted publickey for targetserveruser from 192.168.55.55 port 33180 ssh2: RSA 3c:40:a1:dc:6d:05:1e:27:6b:b2:b5:98:f8:58:b6:96
Jul  1 10:26:28 myuser sshd[15058]: pam_unix(sshd:session): session opened for user targetserveruser by (uid=0)
Jul  1 10:26:28 myuser sshd[15061]: Received disconnect from 192.168.55.55: 11: disconnected by user
Jul  1 10:26:28 myuser sshd[15058]: pam_unix(sshd:session): session closed for user targetserveruser
Jul  1 10:26:28 myuser sshd[15064]: Accepted publickey for targetserveruser from 192.168.55.55 port 33181 ssh2: RSA 3c:40:a1:dc:6d:05:1e:27:6b:b2:b5:98:f8:58:b6:96
Jul  1 10:26:28 myuser sshd[15064]: pam_unix(sshd:session): session opened for user targetserveruser by (uid=0)
Jul  1 10:26:28 myuser sshd[15071]: Received disconnect from 192.168.55.55: 11: disconnected by user
Jul  1 10:26:28 myuser sshd[15064]: pam_unix(sshd:session): session closed for user targetserveruser

The log shows there is definitely a different process taking place. Even though the authorised keys is present on both runs with the same permission.

Is there another file somewhere that would need to be updated?

0

I think it's normal. Did you have installed keychain on the other server? Normally you need to enter the passphrase on every connection you try.

If you mean you need always the user password of the remote server try this to add the ssh keyfile:

ssh-add ~/.ssh/id_rsa

(Keychain is a tool which saves the password, so you didn't have to enter it on every ssh connection)

  • The other server has a similar script and I copied the authorised_keys file to the other server and gave it the same permissions as before. Is that the key chain you are referring to? – algorhythm Jun 30 '16 at 15:06
  • Ok, let's try this way. There should be a file called authorized_keys. In this file there should be your public key. To connect to the server you have to use te username of the new server and your private key has to been on the old server. For exaple: <pre> OLD: private_rsa_key NEW: authorized_keys To connect: ssh userofthenewserverwithauthorizedkeys@newsever</pre> – Marcusg562 Jun 30 '16 at 15:13
  • The file is there and the usernames are exactly the same as before but still it prompts for a password – algorhythm Jun 30 '16 at 15:17
  • For mee it seems as your Public Key is missing. Pleas doing the following: 1. on the new server: cp -p authorized_keys then switch to the existing one and make ssh-copy-id username@server and add the new key. 2. Please compare the two files if there are differences. – Marcusg562 Jul 1 '16 at 8:02
  • The authorised keys are the same. I've printed the contents of the secure log in the question above – algorhythm Jul 1 '16 at 10:37
0

Please show me the content of the file /etc/ssh/sshd_config. Perhaps you've forgotten to enable SSH login with PubKey and/or RSA?

And please also try to connect from the new server to localhost via:

ssh -v localhost

and copy the Output WITHOUT Keys inside

  • Turns out it was an SE Linux issue! restorecon -vR /home/myuser/.ssh solved it – algorhythm Jul 1 '16 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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