Ubuntu

How To Enable OpenSSH on Ubuntu 24.04

Enable OpenSSH on Ubuntu 24.04

OpenSSH or open secure shell protocol provides secure communication channels while communicating over potentially insecure networks. OpenSSH represents the practical implementation of the SSH protocol, relying on both the client and server components.

The primary use for OpenSSH on Linux-based operating systems is to access the command line interface remotely of the client machine. By doing this, you can execute various commands and transfer data as well. To use this protocol on Ubuntu 24.04 not only do you have to install it first but also have to enable it and this guide is about enabling the OpenSSH service.

Outline:

How To Enable OpenSSH on Ubuntu 24.04

The OpenSSH still stands out over other communication mediums as it comes with strong encryption algorithms which are difficult to crack. It uses public-key cryptography for authentication including support for a wide range of key types, thus providing better security and performance. On Ubuntu 24.04 it doesn’t come preinstalled so you have to install it via apt:

sudo apt install openssh-server -y

Installing the OpenSSH server automatically installs the client as well but if you need your system for only accessing other systems then you can install only the client and for that execute:

sudo apt install openssh-client

After the installation is complete now enable the SSH service on Ubuntu:

sudo systemctl enable --now ssh

After enabling the service verify its status through the systemctl utility:

sudo systemctl status ssh

If by any means the service is still not active then try starting it, usually the ssh service automatically starts upon enabling it:

sudo systemctl start ssh

To ensure the proper functioning of SSH service it has to be allowed via a firewall as it might block the communications except port 22:

sudo ufw allow sshd

Once the rules are added verify them by checking the status of the firewall and afterward reload the firewall to apply the changes:

sudo ufw status

Accessing Ubuntu 24.04 Through OpenSSH

The OpenSSH is now enabled and you can access your Ubuntu 24.04 on any other system. For that first find out the IP address of your system:

ip a

Now just use the SSH command sling with the username and the IP address of your system on the host system:

ssh USERNAME@IP_ADDRESS

Here, I have accessed Ubuntu 24.04 on Debian 12 through SSH protocol. On the first login, the system will ask for confirmation to proceed, enter yes:

Now if you want to exit the remote device then execute:

exit

Accessing a System From Ubuntu 24.04 via OpenSSH

In the below image, I have accessed Debian 12 from Ubuntu 24.04 using the same command used for accessing Ubuntu 24.04 from Debian 12:

Setting up a Custom Port for SSH on Ubuntu 24.04

By default, the SSH service uses port 22 for communication which makes the network vulnerable to cyberattacks and sometimes it can cause port conflicts in case you are using NAT configuration for multiple servers. To change the port for SSH open the SSHd_config file in any editor:

sudo nano /etc/ssh/sshd_config

Here you can set the port number from 1024 to 65535, the reason behind keeping the number in this range is to strike a balance between avoiding reserved ports and minimizing the risk of collisions. Here, I have selected port number 1046:

Now restart the SSH service to apply the port changes:

sudo systemctl restart sshd

To enable SSH communication over the new port, you have to allow it through the firewall and for that execute:

sudo ufw allow 1046/tcp

Now verify the rules added for the new port and then reload the firewall:

sudo ufw status

sudo ufw reload

Now use the set port to access the server from Ubuntu by executing:

sudo ssh -p 1046 USERNAME@IP_ADDRESS

Note: The SSH is a client-side tool that is used for system administration file transfers and communication across untrusted networks. Whereas sshd is the server-side daemon that listens to incoming connections via SSH protocol. It handles user authentication, encryption terminal connections, and tunneling.

Conclusion

To enable OpenSSH on Ubuntu 24.04 you first need to install it via its default package installer and then enable it through systemctl command. By default, it uses port 22 which can be changed to a custom port number ranging from 1024 to 65535. Further, to access any system from Ubuntu 24.04 use the server IP address, its username along with the ssh command.

Similar Posts