
How to Fix SSH After a Debian 12 Install
Install and enable OpenSSH on Debian 12, correct common sshd_config typos, and restart the SSH service safely.
Overview
After a fresh Debian 12 installation, SSH may not be installed, enabled, or configured the way you expect. The commands below install OpenSSH Server, enable it at boot, and fix common configuration mistakes.
Install OpenSSH Server
sudo apt update
sudo apt install sudo openssh-server -y
Check the SSH service
sudo systemctl status ssh
If the service is not running, start it and enable it at boot:
sudo systemctl enable --now ssh
Edit sshd_config
Open the server configuration file:
sudo nano /etc/ssh/sshd_config
Use correct OpenSSH directive spelling and capitalization. For example:
Include /etc/ssh/sshd_config.d/*.conf
PermitRootLogin yes
KbdInteractiveAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
For better security, keep PermitRootLogin no and log in with a sudo user whenever possible. Only enable root login if you have a specific reason and understand the risk.
Validate and restart SSH
Before restarting, test the configuration syntax:
sudo sshd -t
If no errors are returned, restart SSH:
sudo systemctl restart ssh
Firewall check
If you use UFW, allow SSH through the firewall:
sudo ufw allow OpenSSH
sudo ufw status
Keep your current console session open while testing a new SSH login, so you can revert the change if remote access still fails.


