Check Syntax Errors before Restarting Server

OpenSSH / OpenBSD Secure Shell – is default secure shell for encrypted communication sessions over a computer network using the ssh protocol. In some cases, you need make ssh configuration changes, let's say, you want to change remote server's sshd conf file  /etc/ssh/sshd_conf. If there is an error in configuration, sshd server may not start properly, or no remote login allowed at al.

How to avoid it without restart sshd service?

OpenSSH Test Mode

OpenSSH has test mode option. Use the -t option to check the validity of the configuration file and sanity of the keys. This is useful for updating sshd reliably as configuration options may change.After making changes to config file, type the following command run syntax check on configuration file, enter:

 $ sudo /usr/sbin/sshd -t
# sshd -t

/etc/ssh/sshd_config: line 25: Bad configuration option: PermitRootLogins /etc/ssh/sshd_config: terminating, 1 bad configuration options

If there is error, it will show on screen. Otherwise it will not display any message:

 $ sudo /usr/sbin/sshd -t
$ echo $?


If there is error on line # 25, edit config file using vi text editor, enter:

 #vi +25 /etc/ssh/sshd_config

Fix the error then try test mode again.

Note that test mode can be done while running the OpenSSH daemon (sshd). If there is no error, simply type a restart sshd command:

 # service sshd restart
# /etc/init.d/ssh restart

Or on RHEL7

systemd restart sshd