Try ssh-add
, you need ssh-agent
to be running and holding your private key
(Ok, responding to the updated question, you first run ssh-keygen
to generate a public and private key as Jefromi explained.. You put the public key on the server. You should use a passphrase, if you don't you have the equivalent of a plain-text password in your private key. But if you do, then you need as a practical matter ssh-agent
as explained below.)
You need to be running ssh-agent
in the background when you log in, and then the first time you log in, run ssh-add
to give the agent your passphrase. All ssh-family commands will then consult the agent and automatically be able to use your private key.
On GNOME and KDE systems, ssh-agent
is probably already launched automatically for you. I will go through the details in case, like me, you also have a Cygwin or other windows environment where this most certainly is not done for you.
Start here: man ssh-agent
.
There are a multitude of ways to automatically run the agent. As the man page explains, you can either run it so that it is a parent of all the other processes and arrange for the environment variables it provides (for interprocess contact) to automatically be in all child environments, or you can run the agent as an ordinary child, save the enviroment settings in a file, and source that file in every shell when they start.
My Ubuntu install automatically did the agent launch setup, so all I had to do was run ssh-add once every time I reboot. Try running ssh-agent
and see if it works, if so, then you just need to do that once per reboot.
My Cygwin system needed it done manually, so I did this in my .profile and I have .bashrc source .profile:
. .agent > /dev/null
ps -p $SSH_AGENT_PID | grep ssh-agent > /dev/null || {
ssh-agent > .agent
. .agent > /dev/null
}
The .agent
file is created automatically by the script; it contains the environment variables definitions and exports. The above tries to source the .agent file, and then tries to ps(1)
the agent. If it doesn't work it starts an agent and creates a new agent file. You can also just run ssh-add
and if it fails start an agent.