I accidentally killed my ssh-agent, how do I restart it without having to reconnect ?

I tried this but it does not work :

$ eval $(ssh-agent -s)
Agent pid 8055

Then, I open a new Gnome terminal with CTRL+SHIFT+N from the previous terminal window and type :

$ ssh-add
Could not open a connection to your authentication agent.

But if I open a new Gnome terminal from my first Gnome terminal by typing :

$ gnome-terminal &

then this new window is able to connect to the ssh-agent.

Is it not possible for all my Gnome terminals to "see" the ssh-agent without having to reconnect to the PC/server ?

3 Answers 3


This doesn't work as you supposed. ssh-agent overwrites the configuration.


Find agent:

eval "$(ssh-agent -s)"

Agent pid 9546

Kill PID:

kill -9 9546


ssh git@gitlab.com-test

ssh git@gitlab.com

It should work now.


Try restart using the following command:

sudo service ssh restart

The private/public RSA SSH keys are located in ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub, respectively. You can transfer the public key to another machine to connect to it through public key authentication. This can be done via ssh-copy-id like so:

ssh-copy-id username@host

Or you can append your public key (id_rsa.pub) to the server's /home/username/.ssh/authorized_keys file, which is in essence what ssh-copy-id does.

  • 7
    This command does not restart the ssh-agent, it only restarts the ssh service
    – SebMa
    May 12, 2019 at 22:07
killall ssh-agent; eval `ssh-agent`
  • 2
    Welcome to the site, and thank you for your contribution. Would you mind adding some explanation on how that solves the OPs problem? Also, please note that the "backtick" notation for command substitutions is deprecated, and the $( ... ) syntax is recommended instead.
    – AdminBee
    Aug 19, 2020 at 12:59
  • 1
    I have my doubts that this would "restart (ssh-agent) without having to reconnect"; perhaps you could elaborate?
    – Jeff Schaller
    Aug 19, 2020 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.