Quick reference for creating SSH keys
Creating the Key
Run the following command in a terminal:
ssh-keygen -t rsa -b 4096 -C "email@example.com"
Follow the steps and type a secure passphrase.
Using the SSH agent
Typing the passphrase every single time we use the key can be a bit exhausting, fortunately we can use a ssh agent to solve this problem. Run the following command in terminal to spawn the agent.
eval "$(ssh-agent -s)"
Now add your key to the agent:
Note.- the flag
-l can be used to list the fingerprints of all identities currently represented by the agent.
Using Keychan to spawn the agent automatically
So far we were able to connect to our ssh server automatically during the current session, but the agent will be removed when we logout. If we are looking for persistence we can use keychan and introduce the passphrase only when we start or reboot the server.
sudo apt-get install keychain
.bash_profile with your text editor:
and type the following line:
eval `keychain --eval --agents ssh id_rsa`
This will add the id_rsa to keychan. The next time you login you will see a screen similar to this, asking for the passphrase:
* keychain 2.8.1 ~ http://www.funtoo.org * Found existing ssh-agent: 11234 * Known ssh key: /home/ubuntu/.ssh/id_rsa Enter passphrase for /home/your_user/.ssh/id_rsa:
Introduce the passphrase and we are done.