Cannot restart SSH after adding host entry in sshd_config

Abstract: Resolve SSH restart failures after editing sshd_config by validating syntax with sshd -t to identify and fix configuration errors.

Created: 2026-07-28 by

Restarting SSH after modifying sshd_config typically fails due to syntax errors or invalid directives introduced during editing. The most effective solution is to validate the configuration file using sshd -t before restarting the service, which identifies specific line numbers and error types allowing for precise corrections.

Understanding the Restart Failure

When you edit the /etc/ssh/sshd_config file, even a single misplaced character, an unknown directive, or an incorrect value can prevent the SSH daemon from starting. Unlike many other services that might ignore bad settings with a warning, OpenSSH is strict. If the configuration parser encounters an issue, it aborts the startup process entirely to maintain security integrity. This results in the service failing to restart, often leaving you without remote access if you are connected via SSH. The error messages provided by the system are usually verbose enough to pinpoint the exact cause, but they require careful reading. Common issues include typos in directive names, such as writing PubkeyAuthenticaton instead of PubkeyAuthentication, or using values outside the accepted range for boolean or integer parameters. Additionally, adding host-specific entries incorrectly can disrupt the global parsing logic. It is crucial to understand that the order of directives matters less than their validity, but certain files like authorized_keys must exist and have correct permissions for key-based authentication to function after a restart.

Validating Configuration Syntax

Before attempting to restart the service again, you must verify that the new configuration is syntactically correct. The standard method for this is using the built-in test mode of the SSH daemon. Run the following command in your terminal:
sudo sshd -t
This command does not start the service; it only parses the configuration files and checks for errors. If the configuration is valid, the command returns silently with no output. If there is an error, it will print a message indicating the file name, line number, and a description of the problem. For example, you might see an output like:
/etc/ssh/sshd_config line 45: Unsupported option "BadDirective"
This output tells you exactly where to look. You should open the configuration file in a text editor, navigate to line 45, and correct the directive. Once corrected, run sshd -t again until it produces no output. This step is essential because it prevents the service from entering a broken state repeatedly.

Common Host Entry Errors

The title mentions adding a "host entry," which often refers to configuring host-specific blocks within the SSH client configuration rather than the server configuration. However, users sometimes confuse ssh_config (client) with sshd_config (server). If you added a block intended for the client into the server configuration, it will fail because the server does not recognize client-side directives like Host or IdentityFile. If you are indeed trying to configure the SSH server, ensure that you are not mixing up global settings with host-specific overrides. In sshd_config, you cannot use the Host keyword to create conditional blocks for different clients in the same way you do in the client config. Instead, you use Match blocks. A common mistake is placing a Match block at the top of the file before any global settings, which can cause unexpected behavior or parsing errors depending on the OpenSSH version. For host-specific server configurations, use the Match directive correctly. For example:
Match User admin
    PermitRootLogin yes
    PasswordAuthentication no
Ensure that the Match block is placed after all global settings. If you place it before, some older versions of OpenSSH may ignore subsequent global settings or fail to parse the file correctly. Always validate these changes with sshd -t to ensure the match conditions are valid.

Checking File Permissions

Another reason for restart failure, though less common with syntax errors, is incorrect file permissions. The sshd_config file itself must be owned by root and have restrictive permissions. If you accidentally changed the ownership or permissions while editing, the daemon may refuse to load the configuration for security reasons. Check the permissions using:
ls -l /etc/ssh/sshd_config
The file should typically show permissions like -rw-r--r-- and be owned by root:root. If the permissions are too open (e.g., writable by group or others), SSH may reject the configuration. Correct the permissions using:
sudo chmod 644 /etc/ssh/sshd_config
sudo chown root:root /etc/ssh/sshd_config
After correcting permissions, test the configuration again with sshd -t and then attempt to restart the service.

Restarting the Service Safely

Once sshd -t confirms the configuration is valid, you can safely restart the SSH service. Use the appropriate command for your Linux distribution. On systemd-based systems like Ubuntu, Debian, or CentOS, use:
sudo systemctl restart sshd
On older SysVinit systems, you might use:
sudo service ssh restart
If the restart fails despite passing the syntax check, check the system logs for more detailed error messages. On systemd systems, view the recent logs with:
journalctl -xeu sshd.service
This log output can reveal issues related to port conflicts, SELinux restrictions, or missing certificates that are not caught by the basic syntax check. If you are unable to reconnect via SSH after a failed restart, ensure you have physical access or a console session available to revert changes if necessary. Always keep a backup of the original sshd_config file before making significant changes.

Frequently Asked Questions

What if sshd -t shows no errors but the service still won't start?

If the syntax check passes but the service fails to start, the issue is likely environmental rather than configurational. Check the system logs using journalctl to identify permission denied errors, port binding failures, or SELinux denials. Ensure that the SSH port is not already in use by another process and that firewall rules allow incoming connections on the specified port.

Can I recover SSH access if I lock myself out?

If you cannot connect via SSH due to a misconfiguration, you must use alternative access methods such as a cloud provider's console, physical keyboard and monitor, or IPMI/iLO interfaces. Once accessed, you can temporarily rename the sshd_config file or restore it from a backup to regain service. Always test configurations in a staging environment or with a secondary connection before applying changes to production servers.

Why does my Match block not apply to specific users?

Match blocks in sshd_config must be placed at the end of the file, after all global settings. If placed earlier, they may not be processed correctly or may override global settings unexpectedly. Ensure the criteria in the Match block, such as User or Address, are spelled correctly and match the actual user or IP connecting to the server.

How do I disable password authentication securely?

To disable password authentication, set PasswordAuthentication no in sshd_config. Ensure that you have configured key-based authentication and tested it successfully before disabling passwords. Also, consider setting PermitEmptyPasswords no and restricting root login to key-based access only to enhance security.

Is it safe to edit sshd_config while connected via SSH?

It is generally safe if you follow best practices, such as validating the configuration with sshd -t before restarting the service. However, always have an alternative means of accessing the server, such as a console session, in case the restart fails and locks you out. Avoid making multiple changes at once so you can isolate the problematic setting if issues arise.

Tags: ssh ssh-keys sshd

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More