Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using chef to build a server.

I generated a passwordless SSH keypair on one server and added the public & private keys to chef. After testing, it worked.

When I provision another server and copy the keys over and try to use them it prompts me for a passphrase.

Running ssh with debug info, I get the message:

"key_parse_private_pem: PEM_read_PrivateKey failed"

How can I copy SSH keys between servers and have them work?

The only thing I can think of is that since the hostname has changed, and I can see the user & hostname in the public key, that it's also in the private key. Somehow the hostname changing prevents the keys from working?

This is my git key - nothing to do with authorized_keys. When I try to clone my repo I get asked for the passphrase.

Here's the process I went through:

  1. Spin up new server on AWS.
  2. Run ssh-keygen as my 'web' user.
  3. Confirm I can clone my git repo.
  4. Copy my id_rsa and files from the AWS instance into chef. Note the permissions.
  5. Spin up a new server and copy over the id_rsa* files into /home/web/.ssh (all perms the same).
  6. Try to clone my git repo - I get prompted for a password. Try to just ssh to git server (bitbucket) - same thing (so not a git issue).
share|improve this question
The usual method of copying them and having them work is scp .ssh/ remote:.ssh/authorized_keys; ssh remote chmod 700 .ssh; ssh remote chmod 600 .ssh/authorized_keys. It would be easier to comment on what was failing for you if you showed us what you've done and seen, instead of telling us. – MadHatter Jun 13 '13 at 7:34
Do you generate a SSH Keypair for each server and then adding on it the main server SSH Public key? Or do you just simply copy the main server SSH Keys? – Dr I Jun 13 '13 at 7:41
@MadHatter: Never copy directly into authorized_keys, you might overwrite the version already there. On most systems, ssh-copy-id is present and comes in handy. – Sven Jun 13 '13 at 7:41
I'm no git expert, but a little googling on setting up servers for ssh authorisation suggests that it is, in fact, to do with authorized_keys. Again, this would all be much more clear if you showed us what you did, what you saw, and what you expected to see, in stead of telling us what you'd done - or what you thought you'd done. – MadHatter Jun 13 '13 at 7:41
Apart from the copying of the file, which isn't necessary unless you want to use the private key to connect to other repos/servers, I'd like to see an ls -la on the .ssh directory on the functioning server, and the non-functioning one. – NickW Jun 13 '13 at 10:48

Your Answer


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

Browse other questions tagged or ask your own question.