List of content you will read in this article:
- 1. What is SSH exactly?
- 2. Prerequisites for enabling SSH on Ubuntu
- 3. How to enable SSH on Ubuntu?
- 4. Log into a remote server using SSH.
- 5. Configure Firewall
- 6. Start, Stop, or Restart SSH service on Ubuntu.
- 7. disable and remove the SSH server on Ubuntu
- 8. Conclusion
What is SSH exactly?
SSH is a popular and free network protocol that establishes communication between two systems far apart. In addition to encrypting all traffic, SSH offers different authentication methods and configuration options to prevent hijacking and eavesdropping attacks.
SSH encrypts every piece of data to ensure that no sensitive information is compromised during the process. So, as a client-server, you can safely transfer sensitive information, run command lines, and use any other network services.
These functions are typically accomplished via insecure tools, including Telnet and RCP, but they transmit users' passwords in cleartext. That’s why OpenSSH is recommended for server and client purposes.
Prerequisites for enabling SSH on Ubuntu
Before you start to do 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 it has already been installed.
The SSH server was already installed on your system based on your Ubuntu version. Before starting the installation process, ensure it has already been installed. 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:
If the "Connection Refused" message appears on your display, you need to start the SSH installation process explained in the next steps.
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. The image below is an example of this:
You may not know the IP address. Don`t worry! You can quickly identify it through the terminal by typing the command:
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.
Decided to change the default port number, but you need to know how. It`s easy. You only need to run a command in Terminal that will configure your firewall and allow traffic via the specified port. UFW is the default firewall configuration tool. 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. Port 2222 is defined in the Configure SSH section.
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 opnessh-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
You can secure a connection through SSH by using the steps listed above. We tried to answer the most frequently asked questions about enabling SSH on Ubuntu systems. Once you’ve completed these, you can work at the command prompt as an administrator on your machine by establishing a reliable and secure protocol named SSH.
People also read: