Git- How to kill ssh-agent properly on Linux

user218867 picture user218867 · Mar 31, 2017 · Viewed 24.1k times · Source

I am using git on linux, when pushing to gitlab, sometimes it either stuck at:

debug1: Connecting to gitlab.com [52.167.219.168] port 22.

or

debug1: client_input_channel_req: channel 0 rtype [email protected] reply 1

debug3: send packet: type 100

Seems restarting linux could solve it, but no body like to reboot machines. So, I am trying to kill ssh-agent process, then restart it.

But the process is always defunct after kill, and then I can't use git via ssh at all, so is there any way to restart the ssh-agent, or solve the issue described above without restarting the machine?


@Update

The ssh keys that I use include key phrase, which I would input on first use of a ssh key.

The issue usually occurs after I bring the Linux desktop back from sleep, thus the network is reconnected, not sure whether this matters?

Again, does any one knows how to kill or restart a ssh-agent agent, without making it become defunct?

Answer

Eduard Mukans picture Eduard Mukans · Jan 6, 2021

You can kill ssh-agent by running:

eval "$(ssh-agent -k)"