Today we will learn How to Install and Enable SSH in Ubuntu. To connect a client securely to a server, the foremost concern is ensuring security. This is especially true for Linux users. SSH is also known as Secure Shell and is the default method for this purpose. This protocol allows them to access and manage remote servers from any location powerfully and efficiently. Are you planning to use SSH now? Follow this article to learn how to enable SSH in Ubuntu and disable it when you don’t need it. But before we begin, let’s see what exactly SSH is.
What exactly is SSH?
SSH is a popular and free network protocol for establishing communication between two systems. In addition to encrypting all traffic, SSH offers various authentication methods and configuration options to prevent eavesdropping and eavesdropping attacks. SSH encrypts every bit of data to ensure that no sensitive data is compromised during the process. So, as a client-server, you can securely transfer sensitive data, run command lines and use any other network service.
These functions are usually accomplished through insecure tools including Telnet and RCP, but they transmit users’ passwords in clear text. OpenSSH is therefore recommended for both server and client purposes.
Prerequisites for enabling SSH in Ubuntu
Before you start the instructions to install and enable SSH on Ubuntu system, you need to be aware of the below mentioned prerequisites:
- Allow remote computer access.
- Internet connection to download required packages.
- You must have at least one other system on your network. (For example, another computer on your local area network, a remote server connected via the Internet, or a virtual machine running locally.)
- Access to the terminal.
How to enable SSH in Ubuntu?
Before enabling SSH you need to install some packages on your system. Not all Ubuntu versions have the SSH protocol by default. So, follow these instructions to make sure you enable SSH correctly.
Check if it is already installed
It seems that SSH server is already installed on your system based on your Ubuntu version. Before starting the installation process, make sure it is already installed. To test it, use the CTRL+ALT+T keyboard shortcut or click the Terminal icon to open Terminal. Then, use the following command:
ssh localhost
If the “Connection refused” message appears on your display, you need to start the SSH installation process explained in the next step.
Update your Ubuntu system
Before doing anything, make sure you are using the latest Ubuntu version. You can update your system by running the following command:
sudo apt update && sudo apt upgrade
Install the OpenSSH client
You can easily install the OpenSSH client application and related support files on your Ubuntu system by entering this command in a terminal:
sudo apt install openssh-client
Ubuntu requires OpenSSH-Server to be installed to accept an SSH connection. Follow the next steps to do so.
Install the OpenSSH server
After you run the instructions to install the SSH client, you need to accept a connection for an SSH session. Type the N command to install the openSSH-server package on your Ubuntu system:
sudo apt install openssh-server
Enable SSH Server in Ubuntu
The below command will enable SSH server on Ubuntu system:
sudo systemctl enable ssh
In the next step, you need to enable UFW and open the SSH port, because the firewall blocks SSH. Use UFW Firewall to open SSH port 22 and run the following command:
sudo ufw allow ssh
Congratulations you can now use the SSH client to connect to your Ubuntu server when you have an SSH server installed and running.
Log in to a remote server using SSH
After you enable SSH on your Ubuntu system, you can go through the process of logging in to the remote system. Use the “CTRL+ALT+T” keyboard shortcut to open Terminal and run the following command:
ssh username@public_IP -p22
Must Substitute the username and IP address of the Ubuntu system where you installed SSH.
You may not know the IP address. Don’t worry! You can quickly locate it through the terminal by typing the command:
ip a
The public IP address of the computer you installed SSH on will be shown as:

Once you have entered all the information, you will be officially logged in to the server. You can manage it securely from your workstation.
Configure the firewall
I have changed the default port number, but you don’t know how. It’s simple. You just need to run a command in terminal which will configure your firewall and allow traffic through specified ports. UFW is the default firewall configuration tool. Use the following syntax to configure port 2222 for example:
sudo ufw allow from any to any port 2222 proto tcp
If your firewall does not allow traffic to SSH’s private IP address, it may be necessary to allow traffic to SSH’s public IP address. If you use the default port, 22, there is no need to change the port number. Port 2222 is defined on the Configure SSH section.
Start, stop, or restart the SSH service in Ubuntu
To start the SSH service in Ubuntu, type the following command in the Terminal:
sudo systemctl start ssh
To stop, use this command:
sudo systemctl stop ssh
And if you need to restart, use the following command:
sudo systemctl restart ssh
Disable and remove the SSH server in Ubuntu
You may no longer need the SSH server or want to remove or disable it for some reason. The following commands will help you with this:
Temporarily disable SSH in Ubuntu:
sudo systemctl stop ssh
Disable SSH after a full reboot:
sudo systemctl disable ssh
Remove SSH from Ubuntu:
sudo apt-get remove opnessh-server
Ensure that the firewall rule that opens TCP port 22 for SSH is removed using the following syntax:
sudo ufw delete allow ssh
Conclusion
You can secure a connection via SSH using the steps listed above. We have tried to answer frequently asked questions about enabling SSH on Ubuntu systems. Once you’ve done these, you can work in the command prompt as an administrator on your machine by establishing a reliable and secure protocol called SSH.



