On your workstation:
Start the ssh-agent on your workstation if it is not running already.
Check with ssh-add -L
; the error message Could not open a connection to your authentication agent.
means that you need to start the agent:
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-yE5gDiNI3IqX/agent.13754; export SSH_AUTH_SOCK;
SSH_AGENT_PID=13755; export SSH_AGENT_PID;
echo Agent pid 13755;
And follow the printed instructions and set up your environment:
$ SSH_AUTH_SOCK=/tmp/ssh-yE5gDiNI3IqX/agent.13754; export SSH_AUTH_SOCK;
$ SSH_AGENT_PID=13755; export SSH_AGENT_PID;
$ echo Agent pid 13755;
Agent pid 13755
SSH, with agent forwarding enabled, and log in with your password to the host that (will) contain the (hopefully password protected) private key:
$ ssh -A host.example.com
user@host.example.com's password:
On the first server
Only once: You need to generate a the new keypair; see https://security.stackexchange.com/q/143442/77995
[user@host.example.com ~] $ ssh-keygen ***+options***
Only once (for every server and account): You need to copy the public_key of that new keypair from this server and append it to the ~/.ssh/authorized_keys
file on the servers you want to access. You can use the ssh-copy-id helper program to do that for you::
[user@host.example.com ~] $ ssh-copy-id localhost
And repeat for every other server, for all accounts that you will want to log in with using that key (if those servers still support password based logins, otherwise you will need to copy the public key in another fashion):
[user@host.example.com ~] $ ssh-copy-id other-user@other-host.example.com
Every time you restart your workstation and the ssh-agent is restarted: add that identity to your keyring
[user@host.example.com ~] $ ssh-add .ssh/id_rsa # or wherever the private key is stored
Identity added: .ssh/id_rsa (rsa-key-xxx)
and logout:
[user@host.example.com ~] $ logout
Afterwards:
And when you next login ssh from your workstation will use the key stored in the agent for key-based authentication and you won't see a password prompt:
$ ssh host.example.com