How to Install SSH on Ubuntu 24.04

In this blog post we will explain in step-by-step detail how to install SSH on Ubuntu 24.04 OS.

SSH or Secure Socket Shell Access is a network protocol that gives administrators, developers, or regular users a secure way to access the server over an unsecured network. SSH was designed as a UNIX-like operating system to replace Telnet and the unsecured remote UNIX shell protocols. It is used to log into a remote computer’s shell or command line interface and execute commands on a remote server.

This blog post will cover installation, service management, and SSH server configuration. Let’s get things done!

Prerequisites

  • A server running Ubuntu 24.04 OS
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

It is recommended that we update the system packages to their latest versions before we start the installation.

sudo apt update -y && sudo apt upgrade -y

Step 2. Install SSH server

Once the packages are updated, we can continue with the SSH installation. To install SSH, execute the following command:

sudo apt install openssh-server

Step 3. Manage SSH service

Once installed, start and enable the SSH service:

sudo systemctl start ssh && sudo systemctl enable ssh

You should get the following output:

root@host:~# sudo systemctl start ssh && sudo systemctl enable ssh
Synchronizing state of ssh.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable ssh

To check the status of the service, execute the following command:

sudo systemctl status ssh

You will get output similar to this:

root@host:~# sudo systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/usr/lib/systemd/system/ssh.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-06-15 08:17:20 CDT; 14min ago
TriggeredBy: ● ssh.socket
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 56757 (sshd)
      Tasks: 1 (limit: 4613)
     Memory: 1.2M (peak: 3.0M)
        CPU: 183ms
     CGroup: /system.slice/ssh.service
             └─56757 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Jun 15 08:17:20 host.test.vps systemd[1]: Starting ssh.service - OpenBSD Secure Shell server...
Jun 15 08:17:20 host.test.vps sshd[56757]: Server listening on :: port 22.
Jun 15 08:17:20 host.test.vps systemd[1]: Started ssh.service - OpenBSD Secure Shell server.

To restart the SSH service you can use the following command:

sudo systemctl restart ssh

To stop the SSH service you can use the command bellow:

sudo systemctl stop ssh

Step 4. Configure SSH service

By the configuration of the SSH service we mean changing the default SSH port, setting the max authentication login attempts, max sessions, etc. These changes can be made into the configuration SSH file located at /etc/ssh/sshd_config.

Changing the default SSH port is due to better security for the attackers, not to know the default SSH port 22. To change the default SSH port opet the /etc/ssh/sshd_config with your favorite text editor and edit the following lines to look like this:

Include /etc/ssh/sshd_config.d/*.conf

Port 3322
#AddressFamily any
ListenAddress 0.0.0.0
#ListenAddress ::

As you can see we set the port to 3322, and that means that the SSH will listen on port 3322 instead of the default one 22.

Save the file, close it, and restart the SSH service.

sudo systemctl restart ssh

If the SSH service still listens on port 22, then it is worth to restart the whole server:

shutdown -r now

The next login to the server will be with the following command:

ssh root@yourserveripaddress -p 3322

To limit the maximum login attempts and sessions you need to edit the following lines to look like this:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
MaxAuthTries 3
MaxSessions 1

Save the file, close it, and restart the SSH service so the changes take effect.

That’s it. You successfully installed and configured the SSH service on Ubuntu 24.04 on your VPS server. If you liked this post on how to install SSH on Ubuntu 24.04, please share it with your friends and leave a comment below.

Leave a Comment