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 |
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:
Conlcusion
You learned about start and stopping/restarting ssh server on Ubuntu Linux.
🐧 7 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Really? Starting, stopping, and restarting all require the exact same instructions?
Thanks for the heads up, it was a typo. The FAQ has been updated.
Maybe this should be updated with the new ‘service $foo (start|stop|restart)’ offering?
Isnt it suprising that all the restarts have the same syntax. But yes they do.
Stop/Start/Restart the OpenSSH using the following commands
The syntax is:
sudo stop ssh
sudo start ssh
sudo restart ssh
sudo status ssh
Good info…
Thanks
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