How to avoid typing ssh-add everytime

Solution 1:

I have installed keychain.

sudo apt-get install keychain

If you're running bash you need to add a few commands to your .bash_profile If you do not have a .bash_profile create one in your home folder. Add these lines:

### START-Keychain ###
# Let  re-use ssh-agent and/or gpg-agent between logins
/usr/bin/keychain $HOME/.ssh/id_dsa
source $HOME/.keychain/$HOSTNAME-sh
### End-Keychain ###

At the start of a work day I will login. When I open a terminal, I will be prompted once for my passphrase. For all other new terminals and connections I will not be asked for my passphrase again.

Solution 2:

What you are looking for is less secure , but it can be accomplished using public key authentication without the need for ssh-agent. A more secure option is to use public key authentication with a passphrase while turning off password authentication on the ssh server, but this isn't what you asked for. See the link at the bottom of this answer for instructions if you decide to do this instead.

To use ssh without being asked for any passphrase, you need to generate your keypair while leaving the passphrase field blank.

To check if you have already generated a keypair, check for the files id_rsa and id_rsa.pub in your ~/.ssh directory. If they are already there, you can delete them or move them to create a new keypair.

Note, if you delete them you will lose access to any ssh servers you are using then old keys to authenticate to if password authentication is turned off on the server.

To create a new keypair, run the following command:

ssh-keygen -t rsa

Accept the default location for the keys and leave the passphrase blank.

To give your public key to the ssh server you want to connect to, use the following command:

ssh-copy-id -i ~/.ssh/id_rsa.pub username@remotehost

After completing these steps, you will be able to log in to the remote server without a password from the computer you are using.

Reference: http://tombuntu.com/index.php/2008/02/20/public-key-authentication-for-ssh-made-easy/