How To Restart SSH Service under Linux / UNIX

last updated in Categories , , , , , ,

How do I restart SSH service under Linux or UNIX operating systems?

SSH is an acronym for Secure Shell. It is an Internet communication protocol that allows log into Linux or Unix bases systems and runs commands. One can exchange files using a secure channel over an insecure network such as the Internet. OpenSSH is developed as part of the OpenBSD project and by default installed on modern Linux and *BSD family of operating systems including macOS. This page shows how to restart ssh service.

Restart SSH Service Command

The command to restart sshd are as follows (you must login as root user). You must run command as per your Linux distribution or Unix variant.
Restart ssh service in Linux or Unix

CentOS / RHEL / Fedora / Redhat Linux Restart SSH

Type the following command:
# /etc/init.d/sshd restart
One can use the service command:
# service sshd restart
If you are using RHEL/CentOS/Fedora Linux with systemd (e.g. RHEL or CentOS v7/8), enter:
$ sudo systemctl restart sshd

How to restart the SSH in Debian / Ubuntu Linux

Restarting ssh is simple job, exeute:
# /etc/init.d/ssh restart
OR
# service ssh restart
OR
$ sudo service ssh restart
If you are using Debian/Ubuntu/Mint Linux with systemd, use the systemctl command:
$ sudo systemctl restart ssh

FreeBSD Restart SSH

# /etc/rc.d/sshd restart
OR
$ sudo service sshd restart

OpenBSD Restart SSH service

# /etc/rc.d/sshd restart
OR
$ doas /etc/rc.d/sshd restart

UNIX Restart SSH

# kill -HUP `cat /var/run/sshd.pid`
OR
# kill -HUP $(cat /var/run/sshd.pid)
Please note that the location of /var/run/sshd.pid may change. So just search a bit through /var/run/ directory.

OpenSUSE/SUSE Enterprise Linux restart sshd

Type the following command:
$ sudo systemctl restart sshd

Arch Linux restart sshd server

Execute the follwoing command:
$ sudo systemctl restart sshd.service

Command line SSH restart for Apple macOS

Open the terminal application and type the following two commands
$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

OR
$ sudo launchctl stop com.openssh.sshd
$ sudo launchctl start com.openssh.sshd

Slackware Linux restart the SSH server

Restarting ssh is pretty easy on Slackware, just run the following command as root user:
# /etc/rc.d/rc.sshd restart

Conclusion

This page explained how to restart ssh service on Linux or Unix-like operating systems using various options. For more information see the official OpenSSH documents here. Another option is to read more about ssh client and sshd server by typing the following man command:
man ssh
man sshd

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

3 comment

  1. I made an error following what I assumed (yes I know) was starting up a service but in fact I changed permissions. Is there a way to redact the change? I don’t have yum installed (policy) and now cannot start a PuTTy session to load files on a remote server through port 22. I’m at a stand still.

  2. But, why restart the ssh server? To make sure the SSH server takes the new configuration into account, we need to restart the SSH server with the command such as

     /etc/rc.d/rc.sshd restart

    Still, have a question? Get help on our forum!