Scenario: I had setup SSH key with a passphrase  to access all my servers/machines. However, its annoying(also non-productive) to enter passpharse everytime I want to ssh into another machine.

Solution: Use SSH Agent to manage the identity keys(ssh keys) and its password. You can automate this by adding the following code in .bashrc file:

eval `ssh-agent -s`
ssh-add -K ~/.ssh/id_rsa

What the above does is that it will launch a ssh-agent process, which will be used by ssh-add process to add the identity file. “-K” option in ssh-add is responsible to store the passpharse into SSH user keychain, so that you don’t have to input passpharse in every single login.

In most of the Linux based machines, .bashrc file will be executed by default when you launch the terminal. If you are using Iterm2 in MacOS, you might want to set it up explicitly to run by going to Iterm2 Preferences –> Profiles –> Command –> ‘Send text at start’ and enter “source ~/.bashrc” as shown below:

Read more about SSH forwarding:

Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *