How to Configure SSH Server Settings on Ubuntu

To configure the SSH (Secure Shell) server settings on Ubuntu Linux, you must edit a specific system configuration file. This article identifies that file, explains how to safely open and modify it, and details the steps required to apply your changes so that your server remains secure and accessible.

The SSH Server Configuration File

On Ubuntu Linux, the primary configuration file for the SSH daemon (the server-side component of SSH) is:

/etc/ssh/sshd_config

Note: Be careful not to confuse this with /etc/ssh/ssh_config, which is used to configure the SSH client settings, not the server.

How to Edit the Configuration File

Since /etc/ssh/sshd_config is a system-critical file, it is owned by the root user. To edit it, you must use a text editor with administrative privileges (using sudo).

To open the file using the Nano text editor, run the following command in your terminal:

sudo nano /etc/ssh/sshd_config

Once the file is open, you can modify various settings. Some of the most common configurations include:

Applying the Changes

After editing the file, save your changes and exit the text editor (in Nano, press Ctrl+O to save, Enter to confirm, and Ctrl+X to exit).

The changes will not take effect until the SSH service is restarted. Before restarting, it is highly recommended to test the configuration file for syntax errors by running:

sudo sshd -t

If no errors are returned, restart the SSH service with the following command:

sudo systemctl restart ssh

Always keep your current SSH terminal window open while testing the new configuration in a separate window. This ensures you can revert the changes if you accidentally lock yourself out of the server.