How to Enable SSH on Ubuntu 24.04


Secure Shell, also known as SSH, is a network-related service that helps users remotely access a system securely from a desired location. SSH service operates on a client-server model, where communication between client and server is performed through a secure channel. The SSH service utilizes the encryption and authentication mechanism to set up a remote connection with the other computer. After the successful connection, the user can use the remote system’s command-line interface and execute commands.

If you have recently started working on the Ubuntu 24.04 system, you may require accessing the Ubuntu system from a remote location to perform terminal-related tasks. In that case, you will require the SSH service on the Ubuntu system for remote access.

Follow this tutorial to find:

How to Enable SSH on Ubuntu 24.04

Before enabling the SSH on Ubuntu 24.04, you should install the OpenSSH server. The OpenSSH server is an open-source utility for Linux systems responsible for performing SSH-related tasks. The Ubuntu official repository includes the package of the OpenSSH server, and it can be installed through the following command:

sudo apt install openssh-server -y

During the installation, you may be asked whether to install the new version of the configuration file /etc/ssh/sshd_config on the system or go with the locally modified one. You can choose any option that you like, but it is advised to go with the first option which is “install the package maintainer”. After selecting your desired option, press the Enter button to complete the OpenSSH server installation on Ubuntu.

Note: This option may or may not appear on your system, because in most cases, OpenSSH server will create the latest SSH configuration file on your system.

Once you have performed the OpenSSH server installation on Ubuntu, you can enable the SSH service on the Ubuntu system through the below-given command:

sudo systemctl enable ssh

When the SSH service is enabled on Ubuntu, you can start the SSH daemon using the below-given command:

sudo systemctl start ssh

You can confirm whether the SSH daemon is running successfully via the below-given command:

sudo systemctl status ssh

From the above output, the active (running) status ensures that the SSH service is enabled and working on the Ubuntu system.

How to Remotely Access Ubuntu 22.04

To remotely access Ubuntu 22.04 through SSH and perform terminal-related tasks, follow the below-given steps:

Step 1: Find Ubuntu IP Address

To remotely access the Ubuntu system through SSH, first, find the IP address of your system, it can be done using the following command:

hostname -I

Step 2: Open the Terminal on Another Computer

To access the Ubuntu system remotely from another computer, you should follow the below-given syntax and execute it in the terminal of another computer:

ssh username@IP address

 

In the above command, you must change the username and IP address according to your system.

Here, I am using Windows PowerShell to access the Ubuntu system remotely using the ssh command:

When you SSH into the Ubuntu system for the first time, you have to authenticate your host on another computer. It can be done simply by using the yes option when asked to continue connecting. Then enter the password of your Ubuntu system for the current user:

Once completed, you will enter the Ubuntu system command-line interface and be able to execute commands right from another computer.

How to Configure SSH on Ubuntu 24.04

Apart from enabling and accessing the Ubuntu system through SSH, you can configure SSH service to improve your device security. The configurations include changing the default SSH port (22), limiting the number of users, locking users from trying multiple attempts, and more. You can do this by first opening the SSH configuration file on Ubuntu using the below-given command:

sudo nano /etc/ssh/sshd_config

Once you open the SSH configuration file, you can modify it according to your needs. For example, if you want to change the default port number of SSH, simply enable the Port 22 line by removing the # sign and replacing it with the number of your choice.

To limit the number of users for SSH on the Ubuntu system, uncomment the MaxSessions line and replace the default number 10 with your desired number:

If you want to lock the users that attempt to log in to the Ubuntu system through multiple failed attempts, simply uncomment the line MaxAuth tries and replace the number according to your choice:

If you want to log in to the Ubuntu system through SSH as a root user, uncomment the line PermitRootLogin line and replace the prohibit-password with yes, as shown below:

After you are done with the SSH configuration, save the file using CTRL+X, add Y and press Enter, then reload the SSH configuration by restarting the SSH service using the:

sudo systemctl restart ssh

In this way, you can make changes to the SSH configuration file and customize your SSH connection according to your needs.

Conclusion

SSH is a powerful networking protocol that is used to remotely access one system from another system securely. To remotely access the Ubuntu system, you have to enable SSH service. However, before that, you should install the OpenSSH server on the Ubuntu system from the apt command. Then, you can enable SSH from the sytemctl command, start the SSH service, and use the status command to check the active status of SSH on Ubuntu. Once everything is done, you can SSH into the Ubuntu system using the ssh command followed by the username and the IP address of the Ubuntu system. You can also configure SSH on Ubuntu by opening the configuration file and protecting your system by changing the default SSH port, max authentication tries, limiting the number of sessions, and more.

Print Friendly, PDF & Email
Categories