How to Verify the Syntax of the file /etc/ssh/sshd_config

If you have done any changes to the ssh configuration file, we will have to either reload or restart the sshd service. But if you have any syntax error in the file, the ssh service will not start and you might lose access to the server.

To avoid these issues, there is an option in sshd command to verify the syntax of the configruation file /etc/ssh/sshd_config. After making your changes, run this command:

$ sudo sshd -t

If there are no syntax errors, it exits silently. If it find mistakes, it tells you:

$ sudo sshd -t
/etc/ssh/sshd_config: line 9: Bad configuration option: Porotocol
/etc/ssh/sshd_config: terminating, 1 bad configuration options

While the SSH daemon is running, you can correct your mistakes before issuing a reload or restart command. The -t switch stands for test. It does not affect the SSH daemon, it only checks /etc/ssh/sshd_config for syntax errors, so you can use it anytime.

Once you have verified the syntax, you can restart or reload the ssh service. For example:

# systemctl restart sshd
Related Post