Prerequisites
Before restarting SSH, make sure you have:
- SSH access to your VPS (current session will stay connected)
- Root or sudo privileges
💡 Restarting SSH does NOT disconnect your current session. It only affects new connections. This is safe to do.
Method 1: Using systemctl (Ubuntu 16.04+, Debian 8+, CentOS 7+)
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22
Restart SSH:
sudo systemctl restart sshd
For Ubuntu/Debian (sometimes called ssh instead of sshd):
sudo systemctl restart ssh
Check status after restart:
sudo systemctl status sshd
Method 2: Using service command (Older Systems)
sudo service sshd restart
Or:
sudo service ssh restart
Method 3: Using init.d script (Legacy)
sudo /etc/init.d/sshd restart
Reload vs Restart
Reload (gentle, no disconnection of existing sessions):
sudo systemctl reload sshd
Restart (full stop and start):
sudo systemctl restart sshd
Use reload when possible as it doesn't interrupt existing connections.
Verify SSH is Running
sudo systemctl is-active sshd
Should output:
active
Check SSH Listening Port
sudo netstat -tulpn | grep sshd
Test New SSH Connection
Open a new terminal and try connecting:
ssh hxroot@YOUR_SERVER_IP -p 22
Troubleshooting Failed Restart
If SSH fails to restart, check config for errors:
sudo sshd -t
Command output: nothing = OK, error message = fix the error.
View SSH logs:
sudo journalctl -u sshd -n 50
Enable SSH on Boot
Make sure SSH starts automatically after reboot:
sudo systemctl enable sshd
Check if enabled:
sudo systemctl is-enabled sshd
Common Restart Commands by OS
- Ubuntu/Debian:
sudo systemctl restart ssh - CentOS/RHEL 7+:
sudo systemctl restart sshd - CentOS/RHEL 6:
sudo service sshd restart - Alpine Linux:
sudo rc-service sshd restart
✅ SSH service has been restarted. New connections will use the updated configuration.