How to Fix ‘Failed to Start OpenSSH Server Daemon’ in Ubuntu

Managing an Ubuntu server or cloud instance only to find that remote SSH connections are refused, or running sudo systemctl start ssh and receiving the failure message “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” blocks remote administration entirely. The OpenSSH server daemon (sshd) is the primary remote management conduit for Linux systems. Before binding to network sockets and accepting encrypted client sessions, sshd parses its configuration files (/etc/ssh/sshd_config and /etc/ssh/sshd_config.d/), verifies file permissions on private host keys, and validates cryptographic parameters. If an invalid syntax directive was added during hardening, if RSA/ED25519 host keys are missing or zero-byte corrupted, or if an existing process holds port 22, the daemon aborts immediately. This technical troubleshooting guide explains sshd initialization and provides step-by-step methods to restore the SSH server daemon.

Why Does the OpenSSH Server Daemon Fail to Start?

The OpenSSH daemon terminates during startup when core prerequisites fail:

  • Configuration Syntax Errors: Typographical errors, unsupported directives, or invalid parameter values inside /etc/ssh/sshd_config.
  • Missing or Corrupted Host Key Pairs: The server’s unique cryptographic host keys (ssh_host_rsa_key, ssh_host_ed25519_key) in /etc/ssh/ are missing, zero bytes, or have incorrect file permissions.
  • Port Collision on Listening Port: Another service or orphaned sshd process holding exclusive binding rights on port 22.
  • Missing Privilege Separation Directory: The required empty directory /run/sshd missing due to RAM disk initialization failures upon reboot.
  • Incorrect File Permissions on Host Keys: Host private keys must strictly have 600 (read/write owner only) permissions; OpenSSH refuses to start if keys are accessible to other users.

Method 1: Run OpenSSH Syntax and Configuration Test

OpenSSH features an integrated test mode that inspects configuration files and reports exact line numbers containing errors.

  1. Open your local console or terminal.
  2. Execute the sshd syntax test utility:
    sudo sshd -t
  3. If the configuration is valid, the command returns completely blank without printing any text.
  4. If an error exists, sshd -t explicitly prints the line number and offending directive:
    /etc/ssh/sshd_config: line 42: Bad configuration option: PermitRootLogonYes
  5. Open the configuration file using Nano:
    sudo nano /etc/ssh/sshd_config
  6. Navigate to the reported line number, correct the typo (e.g. changing PermitRootLogonYes to PermitRootLogin yes), save with Ctrl + O, and exit with Ctrl + X.
  7. Re-run sudo sshd -t to confirm that all syntax errors are cleared.

Method 2: Regenerate Missing Host Key Pairs

If host keys were wiped during a system update or cloud snapshot re-initialization, regenerating them allows the daemon to start.

  1. Inspect the existing host keys in /etc/ssh/:
    ls -lh /etc/ssh/ssh_host_*
  2. If files are missing or show 0 bytes, delete the corrupted fragments:
    sudo rm -f /etc/ssh/ssh_host_*
  3. Generate a complete suite of fresh cryptographic host keys:
    sudo ssh-keygen -A
  4. Verify that proper strict permissions are enforced on the private keys:
    sudo chmod 600 /etc/ssh/ssh_host_*_key
    sudo chmod 644 /etc/ssh/ssh_host_*_key.pub
  5. Start the SSH service:
    sudo systemctl start ssh

Method 3: Ensure the Privilege Separation Directory Exists

OpenSSH requires an empty, root-owned directory at /run/sshd to execute chrooted privilege separation processes.

  1. Check if /run/sshd exists:
    ls -ld /run/sshd
  2. If the command returns “No such file or directory”, create it manually:
    sudo mkdir -p /run/sshd
    sudo chmod 0755 /run/sshd
  3. Attempt to start the service again:
    sudo systemctl restart ssh

Method 4: Check for Port 22 Conflicts

If another daemon or lingering SSH session holds the listening port, sshd cannot bind its network socket.

  1. Inspect what process is currently listening on port 22:
    sudo ss -tulpn | grep :22
  2. Alternatively, use lsof:
    sudo lsof -i :22
  3. If an orphaned process is holding the port, terminate it using its Process ID (PID):
    sudo kill -9 PID
  4. Start the SSH daemon:
    sudo systemctl start ssh

Method 5: Check Systemd Journal Logs for Detailed Diagnostics

If the service continues to fail, checking the systemd service journal reveals underlying kernel or SELinux/AppArmor blocks.

  1. View the detailed startup journal logs:
    sudo journalctl -xeu ssh.service --no-pager
  2. Look for log entries indicating AppArmor profile denials, missing libraries, or port binding permissions.
  3. Once the specific issue is rectified, enable and start the service to ensure it survives future reboots:
    sudo systemctl enable ssh
    sudo systemctl restart ssh
    sudo systemctl status ssh

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.