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.
Steps to test OpenSSH configuration file:
- Open terminal application.
- Open your sshd_config file using your preferred text editor.
$ sudo vi /etc/ssh/sshd_config [sudo] password for user:
- Make changes, save and exit editor.
# Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server PrintMotd not
- Validate the configuration file syntax with sshd.
$ 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
- Correct errors in the sshd_config file and retest.
$ sudo sshd -t $
- Restart the SSHd service to apply the changes once no errors are detected.
$ sudo systemctl restart sshd
Author: Mohd
Shakir Zakaria
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Discuss the article:
Comment anonymously. Login not required.