How to Fix Failed to Start OpenSSH Server Daemon in Ubuntu

The OpenSSH server daemon (sshd.service) is the primary gateway for remote terminal access, secure automation, and systems administration across Ubuntu and Debian servers. However, following configuration changes, package updates, or server reboots, administrators can encounter the critical service alert: Job for ssh.service failed because the control process exited with error code. This prevents all inbound SSH connections, locking out remote engineers.

Why Does the OpenSSH Server Daemon Fail to Start?

The SSH daemon enforces strict configuration syntax, cryptographic key integrity, and socket ownership before opening network ports. Primary causes of service failure include:

  • Syntax Errors in /etc/ssh/sshd_config: Typographical mistakes, invalid directives, or unsupported ciphers in configuration files.
  • Port Binding Conflicts: Another service or rogue SSH process already bound to port 22 or your custom SSH port.
  • Missing or Corrupted Host Key Pairs: The server cryptographic host keys (ssh_host_rsa_key, ssh_host_ed25519_key) missing or holding invalid permissions.
  • Strict Directory Permissions: Incorrect ownership on /var/run/sshd or the root privilege separation directory.
  • AppArmor or SELinux Security Violations: Security policies blocking sshd from binding to non-standard custom ports.

Method 1: Test sshd Configuration Syntax via CLI

The sshd -t command parses configuration directives without starting the daemon, immediately highlighting invalid lines.

  1. Open a local terminal console or access the server via out-of-band IPMI/VNC console.
  2. Execute the configuration test command:
    sudo sshd -t
  3. If an error exists, the output will specify the exact line number and directive (for example: /etc/ssh/sshd_config line 35: Bad configuration option: PermittRootLogin).
  4. Open the file in a text editor:
    sudo nano /etc/ssh/sshd_config
  5. Correct the error, save the file (Ctrl + O), exit (Ctrl + X), and re-run sudo sshd -t until it returns zero output.

Method 2: Check for Port 22 Socket Conflicts

If another process has bound to port 22, the SSH daemon cannot establish its listening socket.

  1. Check which process is listening on port 22:
    sudo ss -tulpn | grep :22
  2. If an old or orphaned sshd process is lingering, terminate it:
    sudo killall sshd
  3. Alternatively, if another application is using port 22, change your SSH port inside /etc/ssh/sshd_config (e.g. Port 2222).
  4. Restart the service:
    sudo systemctl restart ssh.service

Method 3: Regenerate Missing SSH Host Keys

If server host keys were deleted or corrupted during a system snapshot, sshd terminates immediately on startup.

  1. Check if host keys exist in the configuration directory:
    ls -la /etc/ssh/ssh_host_*
  2. If host key files are missing, regenerate all default keys:
    sudo ssh-keygen -A
  3. Ensure secure file permissions on private keys:
    sudo chmod 600 /etc/ssh/ssh_host_*_key
    sudo chmod 644 /etc/ssh/ssh_host_*_key.pub
  4. Restart the SSH service:
    sudo systemctl restart ssh.service

Method 4: Fix Privilege Separation Directory Permissions

The SSH daemon requires /run/sshd to exist with strict root ownership.

  1. Ensure the privilege separation directory exists:
    sudo mkdir -p /run/sshd
  2. Set correct ownership and permissions:
    sudo chmod 0755 /run/sshd
    sudo chown root:root /run/sshd
  3. Verify that the service transitions into an active (running) status:
    sudo systemctl status ssh.service

Get the best tech tips delivered straight to your inbox.

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