Skip to main content
3 of 7
Formatting
Chris Davies
  • 128.4k
  • 16
  • 179
  • 324

Here is a simple example to find PID of ssh-agent for current user without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

P.S. I've only tested these commands on Ubuntu. Also you need to know full path of the executable you are searching such as /usr/bin/ssh-agent in this examples