Applies to: OpenSSH server on Ubuntu 26.04 and 24.04, Debian 13, AlmaLinux and Rocky Linux 9 and 10; restart, reload and failure tested with OpenSSH 10.2p1 on Ubuntu 26.04.1 (systemd 259); service units checked on Ubuntu 24.04.5 (OpenSSH 9.6p1), Debian 13.7 (OpenSSH 10.0p1), AlmaLinux 9.8 and 10.2 and Rocky Linux 10.2 (OpenSSH 9.9p1)
The SSH server is a systemd service, but its name depends on the distribution. Check the configuration first, then restart:
sudo sshd -t && sudo systemctl restart ssh # Ubuntu, Debian sudo sshd -t && sudo systemctl restart sshd # AlmaLinux, Rocky Linux, RHEL
Your current SSH session stays connected during the restart, so you can run this over SSH. Keep that session open until a new login works.
ssh or sshd: which name?
- Ubuntu 24.04: only
ssh. In our test,systemctl restart sshdfailed withFailed to restart sshd.service: Unit sshd.service not found. - Ubuntu 26.04 and Debian 13:
ssh, withsshdaccepted as an alias. - AlmaLinux, Rocky Linux and RHEL:
sshd. There is nossh.service.
1. Check the configuration
sudo sshd -t
No output means the files are valid. A mistake is reported with the file and line; fix it before you restart anything:
/etc/ssh/sshd_config.d/50-test.conf: line 1: Bad configuration option: PasswordAuthentcation /etc/ssh/sshd_config.d/50-test.conf: terminating, 1 bad configuration options
To see the value sshd will actually use for a setting, run for example sudo sshd -T | grep -i passwordauthentication.
If sshd -t answers Missing privilege separation directory: /run/sshd, the service is stopped (systemd removes that folder when it stops). Create it with sudo mkdir -p /run/sshd and run the check again.
2. Restart or reload
sudo systemctl restart ssh # stop and start the server sudo systemctl reload ssh # reread the configuration without stopping
Use sshd instead of ssh on AlmaLinux and Rocky Linux. Editing the file alone changes nothing: in our test, PasswordAuthentication no took effect for new logins only after a restart or a reload, and a session that was already logged in kept running through the restart. According to the sshd manual, a reload makes sshd reread its configuration by restarting itself.
On Ubuntu and Debian, both commands run sshd -t first. With a broken file, reload stopped with Job for ssh.service failed. while the server kept running with the old settings and logins still worked. That makes reload the safer choice there. The AlmaLinux and Rocky Linux unit only sends the reload signal, without that check, so always run sshd -t yourself first.
3. Check that it worked
systemctl status ssh # sshd on AlmaLinux and Rocky Linux sudo ss -ltnp | grep ':22 '
Then open a new terminal and log in before you close the old session.
Ubuntu: “inactive (dead)” is normal
Ubuntu 24.04 and 26.04 start SSH through ssh.socket: systemd listens on port 22 and starts ssh.service when the first connection arrives. Before that, the status looks like this:
○ ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/usr/lib/systemd/system/ssh.service; disabled; preset: enabled)
Active: inactive (dead)
TriggeredBy: ● ssh.socket
systemctl status ssh.socket shows active (listening), and SSH works. Restarting ssh is enough for most settings, but not for Port or ListenAddress, because the socket owns the port. For those, run sudo systemctl daemon-reload && sudo systemctl restart ssh.socket, as explained in how to change the SSH port safely.
If the restart failed
A restart with a broken configuration printed this on Ubuntu 26.04:
Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xeu ssh.service" for details.
The session you are in keeps working, but new logins fail. In our test they first got Connection reset by 127.0.0.1 port 22. After systemd had tried five times (Start request repeated too quickly), ssh.socket failed as well (service-start-limit-hit) and new logins got Connection refused. A plain systemctl restart ssh then kept failing even after the file was fixed. From the session you still have:
- Read the error:
sudo journalctl -u ssh -n 20(-u sshdon AlmaLinux and Rocky Linux). - Fix the file and run
sudo sshd -tuntil it prints nothing. - Clear the failed state, then start SSH again. On Ubuntu:
sudo systemctl reset-failed ssh.service ssh.socket, thensudo systemctl restart ssh.socket. According to the systemd documentation,reset-failedresets the start counter that otherwise blocks manual starts for a while. - Test a new login.
If you have no session left, log in through the console instead: VNC in Virtualizor for a VPS, or IPMI for a dedicated server. See also SSH connection refused.
Restart the whole server over SSH
If you meant to reboot the server rather than the SSH service, run sudo reboot. Your session closes and you can log in again once the server is back up. See shutdown, poweroff, halt and reboot for the differences.
Official documentation: Ubuntu Server: OpenSSH server.