i0exception
i0exception

Reputation: 392

Getting PID of sshd

I am executing sshd in a bash script using

$ /usr/sbin/sshd

How do I get the process ID of this sshd that I executed?

Upvotes: 3

Views: 10151

Answers (2)

jman
jman

Reputation: 11606

Try this command:

ps aux | grep -e /usr/sbin/sshd | grep -v grep | tr -s " " | cut -d " " -f2

or

cat /var/run/sshd.pid

Upvotes: 3

Jeremy Roman
Jeremy Roman

Reputation: 16355

sshd will typically write a PID file; by default this is at /var/run/sshd.pid. You can use this to find the process ID of the listening sshd process. You should be aware that sshd may fork several subprocesses as it works, so what you want really depends on what you intend to do with it.

Upvotes: 6

Related Questions