SSH restart and kill instances?

Invoking the init.d script should still restart the service:

dermot@porkboy:~$ sudo /etc/init.d/ssh restart
[sudo] password for dermot:
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service ssh restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) and then start(8) utilities,
e.g. stop ssh ; start ssh. The restart(8) utility is also available.
ssh stop/waiting
ssh start/running, process 4877
dermot@porkboy:~$

'service ssh restart' works fine here (11.04). It's worth noting that restarting sshd won't kill existing SSH sessions. When you log into a box via SSH, sshd spawns new processes to handle the session. Restarting sshd will kill the main sshd daemon process (and start it again, obviously) but leave other spawned instances of sshd untouched. You want this behaviour because it makes life a lot easier when you're working with headless servers in distant datacenters!

Now, to answer the rest of your question. Instead of running 'ps -A', try this:

dermot@porkboy:~$ ps -ef | grep ssh
root      2522     1  0 Aug29 ?        00:00:00 sshd: dermot [priv]
dermot    2615  2522  0 Aug29 ?        00:00:04 sshd: dermot@pts/0
root      4655     1  0 10:52 ?        00:00:00 sshd: dermot [priv]
dermot    4756  4655  0 10:52 ?        00:00:00 sshd: dermot@pts/1
root      4887     1  0 10:55 ?        00:00:00 /usr/sbin/sshd -D

This probably accounts for the three sshd processes you're seeing - one for the main sshd daemon and then two (root parent, dermot child) per session. I'm SSHed in from two locations o I have five processes. The pts/X bit relates to the virtual terminal that the session is attached so...

dermot@porkboy:~$ who
dermot   pts/0        2011-08-29 21:32 (williams-mb.local)
dermot   pts/1        2011-08-30 10:52 (192.168.253.109)

... gives us some idea which session is which. So if I wanted to kill the session from my MacBook I'd 'kill -9 2522'.

Tags:

Ubuntu

Ssh