Main Menu

How to Install and Enable SSH on Ubuntu [2026 Guide] 🔐

To securely connect a client to a server, the foremost concern is ensuring security. This is particularly true for Linux users. SSH, known as Secure Shell, is the default method for this purpose a cryptographic network protocol that allows you to access and manage a remote server from any location powerfully and efficiently. Whether you need to enable SSH on Ubuntu for the first time, configure it properly, or disable it when you no longer need it, this guide covers the full lifecycle. But before we get started, let's see what exactly SSH is and why it matters.

What is SSH exactly?

SSH is a popular, free, and open-source network protocol that establishes secure communication between two systems over an unsecured network. It was developed to replace less secure protocols like Telnet and remote shell (RSH), which transmit passwords in cleartext. SSH encrypts every piece of data to ensure that no sensitive information is compromised during the process — so as a client or server administrator, you can safely transfer sensitive information, run command lines, and use any other network services without fear of hijacking or eavesdropping attacks.

SSH uses a combination of symmetric and asymmetric encryption algorithms to provide security to the connection. The client and server exchange public keys, which are used to establish a secure encrypted tunnel in which all data is encrypted. This public-key cryptography provides stronger authentication than a simple username and password combination. Beyond remote shell access, SSH also enables secure file transfers, TCP/IP connection forwarding, and secure tunnels for other protocols such as RDP, VNC, and FTP.

Advantages of Installing SSH on Ubuntu

  • Secure Remote Access: SSH enables encrypted remote access to your Ubuntu machine, allowing you to manage your server or desktop from anywhere without exposing sensitive data.
  • Strong Authentication: SSH relies on public-key cryptography, a more secure method than password-only authentication, reducing the risk of brute-force attacks.
  • Encrypted Data Transfer: All data transmitted through SSH is encrypted end-to-end, making it extremely difficult for attackers to intercept or view transmitted information.
  • Port Forwarding: SSH allows you to forward ports to other machines, giving you secure access to remote services without exposing them directly to the internet.
  • Cross-Platform Compatibility: SSH is compatible with various platforms and operating systems, allowing you to connect to different systems using a single, reliable tool.
  • Free and Open Source: SSH is free, open-source software with a large active community — especially on Ubuntu — so help is readily available when you encounter issues.

Prerequisites for enabling SSH on Ubuntu

Before you start the instructions to install and enable SSH on the Ubuntu system, you need to be aware of the prerequisites mentioned below:

  • Permission to access the remote computer.
  • Internet connection for downloading the required packages.
  • There must be at least one other system in your network. (For instance, another computer on your local area network, a remote server connected via the Internet, or a virtual machine running locally.)
  • Access to Terminal.

How to enable SSH on Ubuntu?

Some packages are required to be installed on your system before enabling SSH. All Ubuntu versions don't have SSH protocol by default. So, follow these instructions to ensure you enable SSH correctly.

Check if SSH is already installed

It's possible that the SSH server was already installed on your system based on your Ubuntu version. Before starting the installation process, verify whether it's already present. To check this out, use the CTRL+ALT+T keyboard shortcut or click on the Terminal icon to open the Terminal. Then, use the following command:

ssh localhost

If the "Connection Refused" message appears on your display, it means SSH isn't running yet and you need to start the installation process explained in the next steps. If you run into issues at this stage, here's how to troubleshoot the SSH Connection Refused error before proceeding.

Update your Ubuntu system

Before anything, ensure that you're using the latest Ubuntu version. You can update your system by running the command below:

sudo apt update && sudo apt upgrade

Install the OpenSSH client

You can easily install the OpenSSH client applications and related support files on your Ubuntu system by entering this command at a terminal:

sudo apt install openssh-client

Installing OpenSSH-server on Ubuntu is necessary to accept an SSH connection. Follow the next step to do this.

Install the OpenSSH server

After you run the instructions for installing the SSH client, you need to accept a connection for the SSH session. Type the following command to install the OpenSSH-server package on your Ubuntu system:

sudo apt install openssh-server

Enable SSH server on Ubuntu

The command below will enable the SSH server on the Ubuntu system:

sudo systemctl enable ssh

During the next step, you need to enable UFW and open the SSH port, as the firewall blocks SSH. Use the UFW firewall to open SSH port 22 and run the following command:

sudo ufw allow ssh

Congratulations. You can use the SSH client to connect to your Ubuntu server now that you have installed and run an SSH server.

Log into a remote server using SSH

After you have enabled SSH on your Ubuntu system, you can go through the process of logging into the remote system. Use the "CTRL+ALT+T" keyboard shortcut to open the Terminal and use the following command:

ssh username@public_IP -p22

Note: Replace the username and IP address of the Ubuntu system on which you've installed SSH. If you're new to this, here's a practical guide on how to connect to SSH terminal with more detailed examples. The image below shows what a successful login looks like:

You may not know the IP address. Don't worry! You can quickly identify it through the terminal by typing the command:

ip a

The public IP address of the computer that you installed SSH will be shown like this:

Once you have entered all the information, you will be officially logged into the server. You can safely manage it from the comfort of your workstation.

Configure SSH (sshd_config)

Ubuntu uses the OpenSSH server, which reads its settings from a configuration file. The default configuration file is located at /etc/ssh/sshd_config. You can edit this file to customize your SSH server settings — for example, changing the default port, disabling root login, or restricting allowed users.

To edit the configuration file, run the following command:

sudo nano /etc/ssh/sshd_config

After making the necessary changes, save the file (Ctrl+O, then Enter) and exit (Ctrl+X). Then restart the SSH service to apply the changes:

sudo systemctl restart ssh

If you're working across different Linux distributions, you might also want to know how to change SSH port on CentOS since the process is slightly different there.

Configure Firewall

If you changed the default port number in the sshd_config file, you need to configure your firewall to allow traffic via the specified port. UFW is the default firewall configuration tool on Ubuntu. Use the syntax below to configure it with the example of port 2222:

sudo ufw allow from any to any port 2222 proto tcp

It may be necessary to allow traffic to SSH's public IP address if your firewall does not allow traffic to SSH's private IP address.

Note: If you use the default port, 22, the port number does not need to be changed. If you're unsure which port SSH uses, here's a quick reference on the default SSH port number and when you should consider changing it. Port 2222 is the example used in the Configure SSH section above.

Start, Stop, or Restart SSH service on Ubuntu

To Start SSH service on Ubuntu, type the following command in Terminal:

sudo systemctl start ssh

To stop, use this command:

sudo systemctl stop ssh

And if you need to restart, use the command below:

sudo systemctl restart ssh

To view the status, run this command:

sudo systemctl status ssh

Disable and remove the SSH server on Ubuntu

You may not need the SSH server any more or want to remove or disable it for some reason. The following commands will help you with that:

Temporarily disable SSH on Ubuntu:

sudo systemctl stop ssh

Disable SSH after rebooting completely:

sudo systemctl disable ssh

Remove SSH from Ubuntu:

sudo apt-get remove openssh-server

Ensure that the firewall rule that opened TCP port 22 for SSH has been removed using the following syntax:

sudo ufw delete allow ssh

Conclusion

You can secure a connection through SSH by using the steps listed above. We've covered the full SSH lifecycle on Ubuntu — from checking if it's already installed, through installation and configuration of both client and server, to making your first remote connection, customizing settings via sshd_config, managing the firewall, and finally disabling or removing SSH when it's no longer needed. SSH is a reliable, encrypted, and versatile protocol that gives you complete control over your remote Ubuntu machine. Once you've completed these steps, you can work at the command prompt as an administrator on your machine by establishing a secure and trusted connection whether for system administration, file transfers, or managing remote services.

If you're setting up SSH on a fresh server, a Ubuntu VPS server gives you a clean environment to start with. For broader Linux workloads, Linux VPS hosting offers flexible plans across multiple distributions. Need graphical remote access instead? You can also Buy Ubuntu RDP for a full desktop experience.

Category: Tutorials Linux

Write Comment