Ubuntu Linux: Start, Stop, Restart, Reload OpenSSH Server

I need to provide a remote access to my Ubuntu Linux based server. How do I start / stop, OR restart the ssh server under Ubuntu Linux operating system using command line options?

You need to run a script called /etc/init.d/ssh to stop, start, and restart the OpenSSH server.
Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements Ubuntu/sudo
Time N/A
You can also use the service command to control a System V init script. If you are using the latest version of Ubuntu such as 12.04 LTS or 13.04+, you need to use upstart job based commands as listed below.

Start / Stop / Restart / Reload OpenSSH Server on Ubuntu

Latest version of Ubuntu such as Ubuntu Linux 16.04 LTS or 18.04 LTS and others use the systemctl command to control ssh server on Ubuntu. Older version use the service command. To find out your Ubuntu Linux version, type:
lsb_release -a
cat /etc/*release*

Sample outputs:

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.10
Release:	17.10
Codename:	artful

Another outputs:

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04 LTS
Release:	20.04
Codename:	focal

Ubuntu Linux: Start OpenSSH Server

Type the following command:
$ sudo /etc/init.d/ssh start
OR
$ sudo service ssh start
For systemd based Ubuntu Linux 16.04/18.04/20.04 LTS or above servers, run:
$ sudo systemctl start ssh

Ubuntu Linux: Stop OpenSSH server

Type the following command:
$ sudo /etc/init.d/ssh stop
OR
$ sudo service ssh stop
Again for systemd based Ubuntu Linux 16.04/18.04/20.04 LTS or above server, enter:
$ sudo systemctl stop ssh

Ubuntu Linux: Restart OpenSSH server

Type the following command:
$ sudo /etc/init.d/ssh restart
OR
$ sudo service ssh restart
For systemd based Ubuntu Linux 16.04/18.04/20.04 LTS or above server, execute:
$ sudo systemctl restart ssh

systemctl command in action on Ubuntu Linux desktop

Ubuntu Linux: See status of OpenSSH server

Type the following command:
$ sudo /etc/init.d/ssh status
## OR ##
$ sudo service ssh status
OR for systemd based Ubuntu Linux 16.04 LTS or above server:
$ sudo systemctl status ssh
Sample outputs:

 ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-05-23 10:12:10 IST; 15h ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 2093 (sshd)
      Tasks: 1 (limit: 38036)
     Memory: 2.5M
     CGroup: /system.slice/ssh.service
             └─2093 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

May 23 10:12:10 nixcraft-wks01 systemd[1]: Starting OpenBSD Secure Shell server...
May 23 10:12:10 nixcraft-wks01 sshd[2093]: Server listening on 0.0.0.0 port 22.
May 23 10:12:10 nixcraft-wks01 sshd[2093]: Server listening on :: port 22.
May 23 10:12:10 nixcraft-wks01 systemd[1]: Started OpenBSD Secure Shell server.

Controlling sshd using upstart based commands (this syntax is no longer works with the latest version of Ubuntu)

Since the script /etc/init.d/ssh has been converted to an Upstart based job, try the following commands to start / stop / restart the OpenSSH server:

Stop/Start/Restart the OpenSSH using the following commands

The syntax is:

sudo stop ssh
sudo start ssh 
sudo restart ssh
sudo status ssh

Sample outputs:

Fig.01: Ubuntu using initctl (upstart) to control sshd process

Conlcusion

You learned about start and stopping/restarting ssh server on Ubuntu Linux.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • ORLY Jul 30, 2008 @ 20:31

    Really? Starting, stopping, and restarting all require the exact same instructions?

  • 🐧 nixCraft Jul 31, 2008 @ 3:42

    Thanks for the heads up, it was a typo. The FAQ has been updated.

  • Alex Beamish Oct 25, 2011 @ 14:22

    Maybe this should be updated with the new ‘service $foo (start|stop|restart)’ offering?

  • Maxim Dsouza May 3, 2012 @ 13:32

    Isnt it suprising that all the restarts have the same syntax. But yes they do.

  • Omkar Panda Jul 4, 2013 @ 5:52

    Stop/Start/Restart the OpenSSH using the following commands

    The syntax is:

    sudo stop ssh
    sudo start ssh
    sudo restart ssh
    sudo status ssh

  • udiantara Sep 24, 2014 @ 5:49

    Good info…

    Thanks

  • Vijay Kumar Kanta Nov 21, 2014 @ 11:08

    If you are one of those hardcore Linux guys, and have installed openssh from source, the only way I found to start the server was..

    root:~# /usr/local/sbin/sshd -d
    (or)
    root:~# /usr/sbin/sshd -d

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.