SSH or Secure Shell is a network communication protocol used for remote login or controlling other remote computers. SSH is used to create a secure connection between the local computer and the remote server. In short, SSH protocol connects two computers securely over an unsecured network. Ubuntu does come built-in with an SSH server but it can be installed manually through the official repository. This article will cover the detailed procedure to install an SSH server on Ubuntu.

How to Install SSH Server on Ubuntu 24.04

SSH server does not come pre-installed on Ubuntu and it is not readily available to be installed. However, Ubuntu includes an SSH server in its official repository and it can be installed using the apt package manager. Check the following steps to install the SSH server on Ubuntu 24.04.

Step 1: Update System Repositories

Before installing the SSH server on Ubuntu, make sure all the local packages are up to date. To do so, press CTRL + Alt + T shortcut key to open the Terminal and run this command:

sudo apt update && sudo apt upgrade

Step 2: Install SSH Server

Once the local repositories are updated, install the SSH server on Ubuntu by running the below command:

sudo apt install openssh-server -y

Step 3: Enable SSH Server

After installing the SSH server, make sure that the SSH server is enabled. If the SSH server is not enabled, run this command to enable it:

sudo systemctl enable ssh

Note: When the SSH server gets enabled, it will continue to run whenever Ubuntu boots up:

Note: To disable the SSH server on Ubuntu, run this command:

sudo systemctl disable ssh

Disabling the SSH server will also stop it from starting at boot:

Step 4: Start the SSH Server

After enabling the SSH server, you can start the SSH server by running this command:

sudo systemctl start ssh

Alternatively, you can also enable and start the SSH server immediately with a single command, which is given below:

sudo systemctl enable --now ssh

Step 5: Verify SSH Server Installation

Once the SSH server is started, you can verify its installation and running status by executing the below command:

sudo systemctl status ssh

How to Configure or Enable the Firewall on Ubuntu 24.04

Till now you have installed the SSH server on Ubuntu and made it run successfully. Now is the time to use the SSH server to establish a connection with the remote computer or server. But, before making a connection with the server, make sure that ufw (Uncomplicated firewall) is active and able to pass the traffic to the SSH server. To enable the ufw firewall and pass the traffic to the SSH server, check the following steps.

Step 1: Enable the UFW Firewall on Ubuntu

First, enable the ufw firewall on Ubuntu for the SSH server by running this command:

sudo ufw enable

Step 2: Allow the SSH Server to Pass the Traffic through the Firewall

Once the firewall is enabled, execute the given command to allow the inbound SSH connections so that traffic can pass through it:

sudo ufw allow ssh

Step 3: Check Firewall Status

After activating the firewall, verify whether it is running and passing the traffic to the SSH server through the execution of the below command:

sudo ufw status

Note: To disable and remove the firewall from Ubuntu by running this command:

sudo ufw delete allow ssh

How to Connect to the Remote Server using SSH on Ubuntu 24.04

Upon completing the previously provided steps, you have installed and enabled the SSH server on Ubuntu. Now, you are all set to connect and log in to the remote server using the SSH server protocol. To log in to the remote server, you must have the server IP address or the domain name, and the user created on the server.

Note: The SSH server must be installed on both the remote computer and the computer through which the user is making a connection.

To log in to the remote server using the IP address, run this command:

ssh username@ip-address

To log in to the remote server using the domain name, run this command:

ssh username@domain-name

How to Configure SSH Server on Ubuntu 24.04

Besides installing and using the SSH server to connect with the remote server, you can also configure or make changes to it. Configuration is often practiced to secure the SSH server by changing its ports and passwords. The SSH server’s configurations are stored in the sshd_config file which you can edit through the nano editor.

However, it is recommended to create a backup of the sshd_config file before making any changes, so in case you corrupted the original file you always have its copy. To create a backup of the sshd_config file run this command:

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.initial

Once the backup of the sshd_file is created, run this command to edit the sshd_file with the nano editor to configure it:

sudo nano /etc/ssh/sshd_config

In the sshd_file configuration file, first of all, change the port number to a more secure one. For instance, change the port number to 50782 to make it more secure. To do so, uncomment the Port line by removing the # symbol and specify the port number 50782:

Note: It is recommended to set the port number from the range of 49152 to 65535:

Moving forward, change the password authentication mode to a more secure one. To do so, uncomment the PubkeyAuthentication by removing the # symbol and specifying the value Yes, as shown below:

You can also remove the exception of only allowing the root user to login to the server, by uncommenting the PermitRootLogin section and specifying the value no to it, as shown below:

Additionally, you can also prohibit the users from login to the server with empty passwords. To do so, locate the PermitEmptyPasswords section and uncomment it by removing the # symbol and specify the value No to it, as shown below:

You can set the maximum number of authentication entries to stop the user from coming up with different combinations. Doing so will protect your system from being used by unauthorized users who do not have the password and save your important data from stealing. To set the maximum number of authentication entries, simply uncomment the MaxauthTries by removing the # symbol and providing it the number of maximum tries, for instance, I have set the maximum authentication tries to 6, as shown below:

To save the changes made to the configurations file, press the CTRL + O shortcut and then press the Enter key.

Once you are done with the SSH configuration settings, run this command to restart the SSH service to save the changes made to the configuration file:

sudo service ssh restart

How to Uninstall SSH Server from Ubuntu 24.04

If you are done with using the SSH server or want to remove it from Ubuntu for any other reason. Check the following steps to uninstall the SSH server from Ubuntu 24.04.

Step 1: Stop the SSH Server

To remove the SSH server, first, stop the SSH server on Ubuntu from running, to do so run the below command:

sudo systemctl stop ssh

Step 2: Disable the SSH Server

Once the SSH server is stopped, then, execute the below command to disable the SSH server on Ubuntu:

sudo systemctl disable ssh

Step 3: Uninstall SSH Server from Ubuntu

After stopping and disabling the SSH server, you can uninstall the SSH server from Ubuntu by running this command:

sudo apt remove openssh-server -y

Conclusion

To install the SSH server on Ubuntu, first, open Terminal and run the apt install openssh-server command with sudo privileges. After that, run the sudo systemctl enable –now ssh command to enable and start the SSH server immediately. To verify the running or installation status of the SSH server, run the sudo systemctl status ssh command. You can configure the SSH server by using the nano editor by running the sudo nano /etc/ssh/sshd_config command. Once configured, run the sudo service ssh restart command to restart the server and save changes. To uninstall the SSH server, first stop and disable the SSH server. After that, execute the sudo apt remove openssh-server command to remove it from Ubuntu.