Ensuring the correct configuration of your SSH server is crucial. A misconfiguration can prevent the SSHd service from starting, potentially locking you out if you're editing the sshd_config file remotely. To avoid this, it's essential to verify the configuration before restarting the service.
Fortunately, SSHd provides a built-in option to test the configuration. This option checks the validity of the SSH server configuration file without applying the changes. If errors are detected, they will be displayed, allowing you to rectify them before restarting the service.
$ sudo vi /etc/ssh/sshd_config [sudo] password for user:
# Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server PrintMotd not
$ sudo sshd -t /etc/ssh/sshd_config line 124: unsupported option "not".
-t Test mode. Only check the validity of the configuration file and sanity of the keys. This is useful for updating sshd reliably as configuration options may change.
Use -f option to test alternate configuration file.
$ sudo sshd -t -f /etc/ssh/sshd_config_test
$ sudo sshd -t $
$ sudo systemctl restart sshd
Comment anonymously. Login not required.