This would be used in a scenario when you must have a passphrase when creating ssh keys. If you don’t have a requirement to use a passphrase just press enter when prompted for one when doing ssh-keygen, and ignore the ssh-agent steps.

Having already installed openssh.

On source machine –

ssh-keygen -t dsa -f ~/.ssh/id_dsa -C user@server

Copy key to target machine –

cat ~/.ssh/id_dsa.pub | ssh user@server 'cat - ~/.ssh/authorized_keys'

or just copy and paste the contents of ~/.ssh/id_dsa.pub into ~/.ssh/authorized_keys on your target server.

Check authentication works (should ask for a passphrase) –

ssh user@server

Add the following to .profile

if [ -z $SSH_AUTH_SOCK ]; then
eval ssh-agent -s
ssh-add ~/.ssh/id_dsa
fi

Restart shell to load agent.

If you get a “Could not open a connection to your authentication agent.” error try this instead :

eval $(ssh-agent)

Test with –

ssh user@server

So at this point the ssh-agent should provide the key to the authentication process and you should not be prompted to enter a passphrase.

If there are problems:

    Check that the ~/.ssh directory and the ~/.ssh/authorized_keys file are set to 600 perms (rw- for owner only).
    Use -vvv options with ssh to show debug information.
    Check hostname resolution in both directions.
    Check sshd is running on both servers.

About troyski

I'm a freelance UNIX engineer working in the UK. I'm married to Tina and between us we have six children. I'm a bit of an Apple fan boy, and all the Windows machines in the house are a thing of the past now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation