Restart SSH service Ubuntu with sudo systemctl restart ssh (or sshd on Ubuntu 22.04 and earlier; Ubuntu 24.04 uses ssh as the canonical service name per Reddit thread). For config changes, use reload instead of restart to avoid dropping active connections. Always validate with sudo sshd -t first.
Table of contents
- The systemd command
- Reload vs restart
- Validate before restart
- Check status
- Enable at boot
- Stop and disable
- Old SysV init command (legacy)
- FAQ
The systemd command
On Ubuntu 22.04 and earlier:
sudo systemctl restart sshd
# or equivalently:
sudo systemctl restart ssh
On Ubuntu 24.04 (uses systemd’s canonical naming):
sudo systemctl restart ssh
Both names work because of a symlink, but ssh is the new canonical name. The team that uses the right name has working restart.
Reload vs restart
Reload re-reads config without dropping connections:
sudo systemctl reload ssh
For most config changes, reload is enough. The team that uses restart for config changes drops active SSH sessions; the team that uses reload keeps them alive.
Validate before restart
sudo sshd -t
Exit code 0 = config valid. Non-zero = syntax error. The team that runs sshd -t first avoids restart-with-bad-config that locks everyone out.
Check status
sudo systemctl status ssh
Shows active state, recent log lines, main PID. The team that verifies has confirmation the service is running.
Enable at boot
sudo systemctl enable ssh
The team that enables the service has SSH start at boot. The team that has it disabled has manual start required.
Stop and disable
sudo systemctl stop ssh
sudo systemctl disable ssh
The team that stops the service (rare - usually only for maintenance) loses remote access. Have a console session open if you need to debug.
Old SysV init command (legacy)
sudo service ssh restart
Still works on systemd via compatibility shim. The team that uses this on modern Ubuntu should switch to systemctl for consistency.
FAQ
Why did systemctl restart sshd stop working in Ubuntu 24.04?
The service was renamed to ssh (canonical systemd name). The team that updates to systemctl restart ssh has working restart.
Will restart drop my active SSH session?
No - systemd’s KillMode=process keeps the per-connection processes alive. Restart only kills the main sshd process; the children handle existing connections.
Can I reload sshd without dropping connections?
Yes - systemctl reload ssh. Re-reads sshd_config without dropping sessions. The team that uses reload for config changes has continuous access.
What if I lock myself out by mistake?
Use cloud provider’s serial console (AWS, GCP, Azure) or a KVM/IPMI for physical access. The team that has a backup access path can recover.
How do I check the systemd unit name on my system?
systemctl list-units | grep ssh shows the running service name. The team that has the right name uses the right restart command.
If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.
Useful related references: