27

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 ?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
SebMa
  • 1,941
  • 4
  • 22
  • 37

3 Answers3

28

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

TO FIX THIS---

Find agent:

eval "$(ssh-agent -s)"

Agent pid 9546

Kill PID:

kill -9 9546

THEN YOU CHECK

ssh [email protected]

ssh [email protected]

It should work now.

Nils
  • 103
  • 4
Rajat jain
  • 431
  • 1
  • 4
  • 9
3
killall ssh-agent; eval `ssh-agent`
vignz.pie
  • 31
  • 2
  • 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](https://unix.stackexchange.com/questions/126927/have-backticks-i-e-cmd-in-sh-shells-been-deprecated), and the `$( ... )` syntax is recommended instead. – AdminBee Aug 19 '20 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 '20 at 13:32
1

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.