SSH (Secure Shell) is a web protocol to create secure communication for transferring and sharing data files.SSH encrypts the data to create a secure connection and safely share the files. To create a secure connection, SSH should be enabled, and a firewall must be configured on the client to transfer and share data. To use the SSH service for remote admin servers, you must manually configure the open SSH server.
This write-up will guide you through setting up SSH keys on Ubuntu 22.04.
- How to Set Up SSH Keys on Ubuntu 22.04?
- Uninstall SSH on Ubuntu 22.04
How to Set Up SSH Keys on Ubuntu 22.04?
We create secure communication by setting up the SSH keys on Ubuntu. For setting up SSH keys on Ubuntu, follow the below steps:
Step 1: Update & Upgrade Core Libraries
Before installing the SSH server to set up SSH keys, update the system repositories using the below-mentioned command:
$ sudo apt update && sudo apt upgrade
The installed packages in the system repositories are updated to the latest version and installed in the system.
Step 2: Install Open SSH Server
For the installation of the open SSH server, execute the following command:
$ sudo apt install openssh-server -y
The SSH server is already installed in the system.
Step 3: Enable SSH
The next step is to enable the SSH service on Ubuntu 22.04 using the below command:
$ sudo systemctl enable --now ssh
The ssh service is enabled now; let’s check its status.
Step 4: Verify SSH status
As the SSH service is enabled, verify the current SSH status by running this command:
$ sudo systemctl status ssh
The output shows the status of the SSH service as “active”, which means SSH is enabled and running.
Step 5: Configure Firewall
We can configure the firewall after enabling the SSH server. To allow the firewall for port “22”, execute the below command:
$ sudo ufw allow 22/tcp
Step 6: Enable the Firewall
To utilize the firewall, we have to enable the firewall first. To enable the uncomplicated firewall (ufw) in Ubuntu 22.04, run the below command:
$ sudo ufw enable
Step 7: Connect to a Remote Server Using SSH
After installing the SSH server and enabling the ufw firewall, we can connect to a remote server using the SSH service.
The general syntax for making a connection to the remote server using the “username” and “ip-address” is as follows:
$ ssh username@ip-address
Note: If you don’t know how to find the IP address, you can use the below command to get your system ip-address:
$ ip address
By using the following command, you can create the connection with the remote user “theo” using the SSH service:
$ ssh email@example.com
The error-free output shows that the SSH key is successfully set up and connected to the remote server.
Uninstall SSH on Ubuntu 22.04
To uninstall SSH from Ubuntu, follow the below steps.
Step 1: Disable SSH
If you want to remove SSH from your system, you need to disable the SSH service first. To disable the SSH service, run the below command:
$ sudo systemctl disable ssh --now
Before uninstalling the SSH from Ubuntu 22.04, make sure the status is “inactive”. To verify the status of SSH, use the following command:
$ sudo systemctl status ssh
The output verifies the status of SSH as “inactive”. Now, let’s uninstall SSH from Ubuntu 22.04.
Step 2: Remove Open SSH Server from Ubuntu 22.04
To remove the open SSH server, execute the below-mentioned command in the terminal:
$ sudo apt remove openssh-server -y
The error-free output shows that the open SSH server is uninstalled from the system.
That’s the end of this guide!
SSH keys can be set up on Ubuntu 22.04 by installing the open SSH server by executing the “$ sudo apt install openssh-server -y” command. To configure the SSH server, enable the SSH service executing “sudo systemctl enable –now ssh” and allow the UFW firewall on port “22” to run “$ sudo ufw allow 22/tcp” commands.
Moreover, use the “$ ssh username@ip-address” command utility to set up a remote connection using the SSH service.