Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to restart SSH on Ubuntu using:

sudo /etc/init.d/ssh restart

but this just gives me:

Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service ssh restart

However, running that gives:

restart: Unknown instance:


ps -A | grep ssh

gives 3 instances.


How do I tell which is my instance, and kill the others? Will this then allow me to restart?

Can anybody help me with this please?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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

'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 (

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

share|improve this answer
+1 for who command. Forgot it absolutely. :) –  HUB Aug 30 '11 at 10:05
Thanks for your response. However it seems that the server is not restarting. I've disallowed root ssh access (and so need to restart the service for changes to take effect), and after attempting to restart, I am still able to ssh in as root –  Chris Edwards Aug 30 '11 at 11:13
Can you give us the output of '[/etc/init.d/|service] ssh restart'? Also, stoopid question but are you editing sshd_config or ssh_config? –  Dermot Williams Aug 30 '11 at 11:19
editing the sshd_config file. Output was:bash: [/etc/init.d/: No such file or directory bash: service]: command not found –  Chris Edwards Aug 30 '11 at 15:11
Chris, Dermot wrote this way because he wanted to give both variants in one phrase. Enter either "/etc/init.d/ssh restart" or "service ssh restart" and paste the output. –  HUB Aug 30 '11 at 16:44

When you restart SSH daemon with

sudo /etc/init.d/ssh restart


service ssh restart

the listening daemon restarts with new configuration options (I assume, you restart it for the new config take effect). All sessions already open remain running with old configuration. To learn, which of ssh sessions is yours, try to execute:

ps -ef | egrep '(ssh|PID)'

You will get one /usr/sbin/sshd with PPID 1 and UID root. This is the listening daemon. All other sshd: user@pts/0 records are user sessions. Look for appropriate session by username and kill the process to terminate this session.

I would recomend to do all this in GNU screen session, so if you make a mistake, you will be able to reconnect and reattach this screen session.

Or I didn't understand the question right.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.