How to restart SSH securely [SSH reboot]
Learn how to restart SSH on your server with our step-by-step guide easily. Whether you’re troubleshooting connectivity issues or updating your configuration, our instructions will help you quickly and safely restart SSH and regain secure access to your system.
Updated: 19 Apr, 23 by Susith Nonis 7 Min
Download PDF
![How to restart SSH securely [SSH reboot]](https://monovm.com/wp-content/uploads/2023/04/how-to-restart-ssh97-main.webp)
List of content you will read in this article:
SSH, or Secure Shell, is a network communication protocol that allows two computers to interact and exchange data. The connection between the two machines is secured by default via ssh, making it acceptable for usage on insecure networks. SSH is frequently used to «login» and execute operations on distant computers, but it may also be used for data transmission. Today we are going to learn How to restart ssh?
What is SSH?
To answer How to restart ssh? We need to know what ssh is. SSH, also known as Secure Shell or Secure Socket Shell, is a network protocol that allows users, notably system administrators, to access a computer securely over an insecure network.
SSH is also the name of a collection of tools that implement the SSH protocol. Secure Shell supports strong password and public key authentication and encrypted data transmission between two computers connected through an open network like the Internet.
Network administrators commonly use SSH to administer systems and programs remotely, allowing them to log in to another computer via a network, execute instructions, and transfer data from one machine to another.
SSH refers to the cryptographic network protocol and the programs that implement it. It employs the client-server architecture, linking a Secure Shell client program, and displays the session to an SSH server, which operates the whole session. Support for application protocols used for terminal emulation or file transfers is frequently included in SSH implementations.
SSH may also construct secure tunnels for other application protocols, such as remotely running X Window System graphical sessions. By default, an SSH server listens on the standard Transmission Control Protocol (TCP) port 22.
How does SSH work?
Secure Shell was designed to replace insecure terminal emulation and login applications like Telnet, rlogin (remote login), and rsh (remote shell). SSH allows the same operations on remote computers, such as logging in and running terminal sessions. SSH may replace file transfer tools like FTP and rcp (remote copy).
SSH is most commonly used to connect to a remote host for a terminal session. That command takes the following form:
For what purposes is SSH used?
SSH is present in all data centers and comes standard with every Unix, Linux, and Mac server. SSH connections have been used to secure various communications between a local workstation and a remote host, including remote access to resources, remote command execution, software patch and update delivery, and other administrative or management duties.
SSH controls routers, server hardware, virtualization platforms, operating systems (OSes), systems administration and file transfer programs and establishes a secure channel between local and remote computers.
The SSH keys, designed to be convenient and function across organizational boundaries, allow single sign-on (SSO) so that users can move between accounts without having to type a password each time.
SSH performs more than only authenticating via an encrypted connection while playing critical roles in identity and access management. Its transmission is always encrypted. Users’ actions are private, whether sharing a file, surfing the web, or performing a command.
Disadvantages of SSH
Before we get into ssh commands and learn how to restart ssh, it’s not wrong to look at its disadvantages. SSH businesses should look at solutions to control host keys saved on client computers. These keys can amass over time, especially for information technology (IT) personnel who require remote host access for administrative purposes.
Because the data stored in an SSH known hosts file can be used to gain authenticated access to remote systems, organizations should be aware of their existence and have a standard process in place for retaining control over the files, even after a system is taken offline, as the hard drives may have this data stored in plaintext.
Shellshock, a security flaw in the Bash command processor, can be performed through SSH, but it is a Bash flaw, not an SSH one.
Poor key management is the most dangerous to SSH users. Organizations can lose control over who may access which resources. Besides, when SSH keys are not created, turned, and removed manually, primarily when SSH is used in automated application-to-application operations, everything is out of the user’s hands.
Learn some SSH commands.
While there are graphical models of SSH, the application is often run via the command line or as part of a script. When run without arguments, such as a destination host or user ID, the ssh command produces a list of SSH command parameters and options.
The most basic SSH command is to run the software and specify the destination host name or Internet Protocol (IP) address:
This will establish a connection to the target, server.example.org. The destination host will react by requesting a password for the user ID associated with the account in which the client is executing. In other words, if the user ID is LYSM, the remote host will request a password for the account LYSM on the remote system.
Besides this basic command, you can use the commands below:
- Sshd
- Ssh-keygen
- Ssh-copy-id
- Ssh-agent
- Ssh-add
- Scp
- Sftp
How to restart SSH service? Use this command!
The restart sshd command is as follows: (you must log in as root user). You must execute the command following your Linux distribution or Unix variation.
$ sudo systemctl restart sshd
As for Debian and Ubuntu, you have multiple options:
service ssh restart
sudo service ssh restart
sudo systemctl restart ssh
How about Windows? Is there a way to restart SSH services?
On Windows, SSH is usually implemented using the OpenSSH server. To restart the OpenSSH server on Windows, you can follow these steps:
Open a PowerShell console with administrator privileges. You can do this by right-clicking on the PowerShell icon and selecting «Run as administrator.»
Type the following command to stop the OpenSSH server:
Wait for a few seconds to ensure that the service has stopped. You can confirm this by running the following command:
This should display the status of the sshd service as «Stopped». Now, type the following command to start the OpenSSH server:
Wait for a few seconds to ensure that the service has started. You can confirm this by running the following command:
This should display the status of the sshd service as «Running». Once the service is restarted, you can connect to the OpenSSH server using an SSH client.
Last words on how to restart SSH!
We are at the end of this article and hope you’ve learned all you wanted to know. We tried to cover every detail and aspect of restarting ssh. Now it’s your time! Did you ever restart your ssh service? Do you know any other way to restart ssh? If yes, please share it with us in the comment section.
People also read:
- What is an SSH KEY?
- How to Connect to SSH with Private Key
- SSH port-forwarding
- How to fix SSH Connection Refused Error
I’m fascinated by the IT world and how the 1’s and 0’s work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited ‘master chef’.
How to Do an SSHD Restart on Linux
Restarting the SSH daemon (sshd) allows you to refresh SSH connections and apply important security changes. In this comprehensive 2500+ word guide, I‘ll explain in detail how to properly restart sshd on Linux.
Whether you need to apply new firewall rules, change ports, load new encryption ciphers, or troubleshoot issues, a clean sshd restart is a critical sysadmin skill.
Follow along below as I show you the key steps and best practices for restarting sshd smoothly and correctly.
What is SSH and How Does it Work?
Before jumping into restarting sshd, let‘s briefly overview what SSH is and how it works under the hood.
SSH stands for Secure Shell, and is a cryptographic network protocol that enables secure remote login and other network services over an unsecured network.
Some key aspects of SSH operation:
- Encryption – SSH uses strong symmetric encryption algorithms like AES, Blowfish, 3DES to encrypt data in transit over the network. This prevents eavesdropping and man-in-the-middle attacks.
- Authentication – SSH relies on public-private asymmetric key pairs to authenticate users. The private key is held by the user, the public key is stored on the server. Users prove their identity by demonstrating possession of the private key.
- Integrity – Data integrity is ensured using cryptographic message authentication codes (MACs) like SHA-1 and MD5. This prevents tampering of data over the connection.
- Port Forwarding – SSH can tunnel other application protocols like HTTP, SMTP, IMAP inside its encrypted connection. This provides security to otherwise insecure protocols.
- X11 Forwarding – SSH enables secure remote graphical sessions by forwarding the X11 protocol. This allows apps with GUIs to be displayed over an encrypted connection.
When an SSH client connects to an SSH server, this process occurs:
- Client and server agree on encryption algorithms, MAC methods, and protocol version through a handshake.
- Server authenticates client using public-private key pair.
- Session keys are exchanged to encrypt subsequent communications.
- Encrypted tunnel is established for safe data transfer.
- Remote terminal session, command execution, file transfer occurs over encrypted tunnel.
- Session ends and connection is closed when finished.
Now that you understand how SSH connections work, let‘s look at why we need to restart the SSH daemon itself occasionally.
When Would I Need to Restart SSHD?
The SSH daemon sshd runs persistently in the background on the remote server you are connecting to. It handles incoming SSH connections, authenticating users, spawning remote shells, enabling port forwarding, X11 forwarding, and tearing down connections when finished.
Here are some common situations where restarting the sshd daemon becomes necessary:
- Applying new configuration – Any changes to sshd_config like listening port, protocol version, ciphers require restarting sshd for changes to take effect.
- Security updates – Loading new keys, cipher suites, MAC algorithms after an OS upgrade or patch to enforce security.
- Change listening port – Changing the listening port for sshd from the default of 22 to a custom port to improve security. This requires a restart to bind to the new port.
- Address issues – Restarting sshd can resolve connectivity issues, non-responsiveness, failures, and lockups. It resets the service cleanly.
- Expiring keys – Rotating out expired host keys and reloading new keys improves security and avoids man-in-the-middle attacks.
- Changing firewall rules – If firewall policies were updated to allow new subnets or block IPs, a restart will load those new rules.
- Troubleshooting problems – If you are seeing authentication errors, protocol mismatches, configuration issues – a restart can help identify the cause.
- Clearing connections – Restarting forces all active SSH connections to close. This can fix hung sessions, kill inactive connections from an attacker.
As you can see a restart gives you a clean slate if the SSH daemon is misbehaving, security needs updating, or configuration changes need applying.
Now let‘s get into how to actually restart that sshd process correctly on Linux!
Step-by-Step Guide to Restarting SSHD
The examples below demonstrate restarting sshd on an Ubuntu 22.04 LTS system but the general principles apply to all major Linux distributions like RHEL, CentOS, Debian, Fedora, Arch, etc.
1. Check SSHD Status
First we‘ll verify that the SSH daemon is currently running with the systemctl command:
systemctl status sshd
This will confirm sshd is active before we restart it. The output should show Active: active (running) :

If sshd is not running, you can start it with:
systemctl start sshd
2. Stop the sshd Service
Now that we‘ve verified sshd is running, we need to stop the current sshd processes cleanly before restarting.
This will disconnect any active SSH sessions so make sure to warn users first!
systemctl stop sshd
This sends a TERM signal to running sshd processes telling them to exit gracefully.
You can confirm sshd has stopped with systemctl status sshd again:
sshd.service - OpenSSH Daemon Loaded: loaded (/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: inactive (dead)
The inactive (dead) status shows it was cleanly stopped.
3. Disable Automatic SSHD Startup
Next we‘ll prevent sshd from automatically starting again after we restart it.
This allows us to keep it stopped until we are ready to explicitly restart it:
systemctl disable sshd
The disable removes sshd from system startup:
Removed /etc/systemd/system/multi-user.target.wants/sshd.service.
This prevents sshd from starting again after we restart the systemd daemon.
4. Make sshd_config Changes (Optional)
At this point, if you need to change the sshd configuration you can edit:
/etc/ssh/sshd_config
For example, to change the listening port from 22 to 2222 for security:
Port 2222
Or only allow SSH Protocol 2:
Protocol 2
Any edits to sshd_config require restarting sshd for changes to apply.
See the section below for more common sshd_config changes.
5. Reload the New sshd Config
If you modified sshd_config , reload the new config into systemd without fully restarting yet:
systemctl reload sshd
This applies the new config while keeping sshd stopped.
6. Restart the SSH Daemon
Now restart sshd which will start it with the new configuration:
systemctl restart sshd
This will fully stop any remaining sshd processes and launch the daemon with your new config and changes.
7. Verify SSHD Restarted Correctly
To confirm sshd restarted properly, check the status again:
systemctl status sshd
You should see output showing sshd as active (running) again, this time with any new changes applied:
sshd.service - OpenSSH Daemon Loaded: loaded (/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-07-14 12:32:01 UTC; 5s ago
Check your SSH connection works and any config changes took effect, like new port binding.
Common sshd_config Settings that Require Restart
Many configurations in /etc/ssh/sshd_config require fully restarting the SSH daemon for changes to take effect.
Here are some of the most common settings that would need an sshd restart:
Port
The port sshd listens on. The default is 22. Changing this requires restarting sshd to rebind to the new port:
Port 2222
ListenAddress
Restricts sshd to only listen for connections on specific addresses. Restart to apply:
ListenAddress 192.168.1.100
Protocol
Specifies minimum SSH protocol version allowed. Restart to enforce:
Protocol 2
Ciphers
Selects permitted symmetric encryption ciphers in order of preference. Restart loads new suite:
Ciphers [email protected],[email protected]
MACs
Sets message authentication code algorithms for data integrity. Requires restart:
MACs [email protected],[email protected]
Banner
Specifies a custom banner file displayed before authentication. Needs restart:
Banner /etc/issue.net
In total there are around 80 different sshd_config options that can alter daemon behavior and security. Always restart sshd after making changes.
Now let‘s look at how to restart sshd without interrupting active connections…
Restarting sshd Gracefully
The systemctl restart sshd command will kill any current SSH sessions as it stops and restarts the daemon.
To restart sshd gracefully, allowing users to disconnect normally, follow this process:
- Reload new sshd_config with systemctl reload sshd
- Stop new SSH connections with systemctl stop sshd
- Wait for all current SSH sessions to complete and disconnect
- Start sshd again with systemctl start sshd
This approach loads the new config, prevents any new logins, but allows existing connections to close cleanly before restarting.
After waiting sufficient time for users to sign out, you can monitor running SSH processes with:
pgrep sshd
Once all sshd processes disappear, restart sshd.
Graceful restarts avoid forcibly terminating user‘s work by letting them exit normally before resetting sshd.
Troubleshooting Issues After Restarting sshd
In some cases, you may encounter issues with SSH connections after restarting the sshd daemon.
Here are some common problems and how to troubleshoot them:
sshd Service Not Found
If you get a «Unit sshd.service not found» error, this indicates the systemd unit file for sshd is missing or corrupted. Reinstall openssh-server package to replace it:
apt install --reinstall openssh-server
Connection Refused
A «Connection refused» error means sshd is not actually running and listening on the port. Verify it is active with systemctl status sshd . If not, restart it.
Authentication Errors
Failed password or publickey authentication could indicate a config issue like invalid or missing keys. Check sshd_config and logs. Consider resetting keys.
Protocol Mismatch
«Protocol mismatch» errors mean the protocol version set on client and server differ. Double check version configs in sshd_config and your SSH client.
Hostkey Mismatch
A hostkey mismatch warning means the server‘s keys changed but your client still has old ones cached. Delete old host keys from ~/.ssh/known_hosts and connect again to cache new keys.
Permission Denied
Permission errors could mean keys have incorrect modes/ownership. Double check 600 for private keys and 644 for public keys.
Connection Times Out
If connections timeout or stall, a firewall could be blocking traffic on new port. Verify rules allow the SSH port through.
Digging into logs at /var/log/auth.log can also provide clues to issues after a restart.
Automating SSHD Restarts
For servers with frequent sshd restarts, you can automate the process using:
Systemd Service
Create a systemd service that runs systemctl restart sshd on a timer or when triggered by another process.
Ansible
Write an Ansible playbook to restart sshd across nodes and include it in a deployment playbook.
SSH Script
Script commands like systemctl stop sshd , systemctl start sshd and execute it remotely over SSH.
Cron Job
Schedule sshd restarts using cron jobs to run at specific intervals or times.
Automation helps ensure consistent and predictable sshd restarts across multiple servers.
Final Thoughts
Restarting the SSH daemon is necessary to cleanly apply security changes, implement new configurations, resolve issues, and improve reliability.
The key steps outlined in this guide include:
- Stopping current sshd processes gracefully
- Disabling automatic sshd startup
- Making sshd_config changes as needed
- Reloading the new configuration
- Fully restarting sshd
- Verifying the service restarted correctly
Following this controlled process allows you to restart sshd smoothly and minimize disruption to users.
Common scenarios requiring an sshd restart include altering ports, loading new ciphers/protocols, replacing expired keys, applying patches, and resolving connectivity issues. Restarting can prevent having to fully reboot the system.
Now you have an easy reference to consult when you need to restart sshd on your Linux systems. Let me know in the comments if you have any other sshd restart tips!
How can I restart the SSH daemon on Ubuntu?
When I type in service sshd restart I get a sshd: unrecognized service error. I do have, in /etc/ssh/ a file sshd_config that I use to set config. I can also putty into the Ubuntu box (it is remote). When I type in /etc/init.d/sshd restart I get No such file or directory Under /usr/sbin/ there is an sshd file, but it is binary. Is something wrong with my sshd? What do I do to fix this? To be clear, I want to be able to type service sshd restart (like all the online tutourials say) to be able to, well, restart my sshd. So that my port changes take effect.
240k 66 66 gold badges 456 456 silver badges 682 682 bronze badges
How do I restart the SSH service?
IMPORTANT — do not install openssh-server on your local machine (laptop/desktop) unless you wish to permit incoming connections from other remote machines . you do NOT need this package to ssh to other machines since ubuntu comes with the Client half of this Server
Aug 29, 2016 at 1:32
7 Answers 7
15.04 and newer:
Use this command:
sudo systemctl restart ssh
To restart the SSH server/daemon.
Going forward with systemd starting with Ubuntu 15.04, you now use this syntax to stop, start, or restart services:
sudo systemctl
57.8k 43 43 gold badges 146 146 silver badges 200 200 bronze badges
answered Jul 18, 2015 at 16:12
Michael Butler Michael Butler
1,598 1 1 gold badge 15 15 silver badges 25 25 bronze badges
Afterwards, check the status of the SSH daemon using sudo systemctl status ssh
Feb 7, 2021 at 14:27
On ubuntu 18 I get Failed to restart ssh.service: Unit ssh.service not found.
Jul 4, 2021 at 5:08
alias sc=’sudo systemctl’ quicker and matches a similar util on Windows. 😉
Oct 11, 2021 at 1:27
Command for restart ssh service is:
sudo service ssh restart
answered Jul 18, 2015 at 18:02
10.5k 6 6 gold badges 31 31 silver badges 44 44 bronze badges
Pre 15.04:
It should be as simple as (tested on a fresh install with openssh-server)
sudo stop ssh sudo start ssh
As it leverages upstart, this is The Best Way™ to do it, rather than using /etc/init.d/ssh, service , or invoking sshd directly. Make sure to run both commands; if you get an error on stop ssh , start ssh anyway and see what it says—the service could already be stopped.
(I would recommend stop / start over restart , unless you are trying to restart a system remotely. If ssh is already stopped, restart will not start it.)
If those commands don’t work, you are probably either experiencing a bug or have tinkered too far with your system, in which case you at least know what the problem isn’t.