This runbook provides procedures for administering, troubleshooting, securing, and recovering Secure Shell (SSH) access on Ubuntu Linux servers.
Applies to:
- Ubuntu Server 20.04 LTS
- Ubuntu Server 22.04 LTS
- Ubuntu Server 24.04 LTS
Services Covered:
- OpenSSH Server (sshd)
- SSH User Authentication
- SSH Key Management
- SSH Access Control
- SSH Incident Response
dpkg -l | grep ssh-serversudo systemctl status sshExpected Output:
Active: active (running)
sudo systemctl is-enabled sshExpected Output:
enabled
sudo systemctl start sshsudo systemctl stop sshsudo systemctl restart sshsudo systemctl reload sshsudo ss -tulpn | grep sshExpected Output:
LISTEN 0 128 0.0.0.0:22
ssh localhostssh username@server-ipConfiguration File:
/etc/ssh/sshd_configsudo cp /etc/ssh/sshd_config \
/etc/ssh/sshd_config.backupBefore restarting SSH:
sudo sshd -tExpected Output:
(no output)
sudo adduser usernamesudo usermod -aG sudo usernamesudo passwd -l usernamesudo passwd -u usernamesudo passwd -S usernamessh-keygen -t ed25519ssh-copy-id username@server-ipcat ~/.ssh/authorized_keyschmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysEdit:
sudo nano /etc/ssh/sshd_configSet:
PermitRootLogin no
PasswordAuthentication no
AllowUsers adminuser cloudadmin
Port 2222
Validate:
sudo sshd -tRestart:
sudo systemctl restart sshsudo ufw statussudo ufw allow 22/tcpsudo ufw allow 2222/tcpsudo ufw reloadUbuntu 22.04+
sudo journalctl -u sshReal-Time Monitoring:
sudo journalctl -fu sshAuthentication Events:
sudo grep sshd /var/log/auth.logFailed Login Attempts:
sudo grep "Failed password" /var/log/auth.logSuccessful Logins:
sudo grep "Accepted" /var/log/auth.logssh: connect to host x.x.x.x port 22:
Connection refused
sudo systemctl status ssh
sudo ss -tulpn | grep sshsudo systemctl start sshOperation timed out
sudo ufw status
ping server-ipVerify:
- Network connectivity
- Firewall rules
- Security groups (AWS/Azure/GCP)
Permission denied (publickey)
ls -la ~/.ssh
cat ~/.ssh/authorized_keysCorrect permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysReinstall key if necessary.
sudo systemctl status ssh
sudo journalctl -xe
sudo sshd -tInvalid sshd_config directive
Restore backup:
sudo cp \
/etc/ssh/sshd_config.backup \
/etc/ssh/sshd_configRestart:
sudo systemctl restart sshVerify:
- SSH service running
- Port listening
- Firewall rule present
- Network connectivity operational
- User account unlocked
- SSH key valid
- Configuration validated
- Logs reviewed
Validation Commands:
sudo systemctl status ssh
sudo ss -tulpn | grep ssh
sudo ufw status
sudo sshd -tEscalate if:
- Root filesystem full
- Suspected compromise
- Repeated brute-force attacks
- Service repeatedly crashes
- Authentication subsystem corruption
- Multiple production servers affected
OpenSSH Documentation
man ssh
man sshd
man sshd_configUbuntu Service Management
man systemctlTo check if a service is already instaled on your linux machine:
- List all installed packages and filter output bu specific package name
dpkg -l | grep <service-name>
For example, to check if open ssh is installed:
dpkg -l | grep openssh-client
- Check version
''' -V '''