Secure Shell, also known as SSH, is a popular tool used to connect to a server through a client. SSH provides secure remote connection and communication between a server and its client, and also enables file transfer over a remote network connection.
In this post, we will walk through a step by step guide on how to enable SSH on CentOS 8 and access its server from a CentOS 8 client machine using SSH remotely. Let’s start by setting up a CentOS 8 server for a remote SSH connection.
Configuring a CentOS 8 server for remote connection
Setting up a CentOS 8 server for remote connection is our top priority.
Step 1. Update the system package repository.
Refresh the system package repository cache by entering the following command:
$ sudo dnf makecache
Update your system packages.
$ sudo dnf upgrade
Step 2. Install OpenSSH server on CentOS 8 server.
After updating the system repository cache and packages, install the OpenSSH server package by entering the following command:
$ sudo dnf install openssh-server
After successful installation, start the “sshd” service if it is not already running.
Step 3. Start the OpenSSH service.
To start the OpenSSH service, enter the following command:
$ sudo systemctl start sshd
Check the status of the service using the command below:
$ sudo systemctl status sshd
Also, enable the OpenSSH service on reboot by typing the command below:
$ sudo systemctl enable sshd
Okay, the OpenSSH service is active and ready to connect. Now we need to start traffic, and for this we need to configure the firewall.
Step 4. Allow the gateway
The firewall will allow any traffic from SSH port 22. To allow the firewall to pass traffic over SSH, enter the following command:
$ firewall-cmd --zone = public --permanent --add-service = ssh
Better to restart your firewall after configuring it.
$ firewall-cmd --reload
The CentOS 8 server is ready for SSH connection. Let’s find out the IP address of the server and access it from the CentOS 8 client machine.
Step 5: Get the IP address of the CentOS 8 server
To get the IP address of your CentOS server, enter the following command:
$ ip a
The IP address of our server is 192.168.12.054. Let’s connect to this machine from a CentOS 8 client machine.
Connect to CentOS 8 server from CentOS 8 client
To connect to a CentOS 8 server follow the step given below:
Step 1: Installing OpenSSH Clients on a CentOS 8 Client Machine
First of all, you need to install OpenSSH clients on your CentOS 8 client machine.
$ sudo dnf install openssh-clients
After installing OpenSSH clients, create and copy SSH key pairs to connect to your CentOS 8 server.
Step 2: Generating SSH Key Pair
To generate an SSH key pair, enter the command below:
Click “Enter”To save the key pair in the specified default directory.
Or, if you’ve already generated a key pair, clickEnter”To overwrite the previously generated key pair.
Enter the passphrase or click “Enter”To enter an empty passphrase.
Okay, the key pair was created successfully, now let’s copy the key pair to the server.
Step 3: Copy the key pair to your CentOS 8 server
To copy the key pair to the CentOS 8 server, enter the following command:
$ ssh-copy-id [email protected]
Don’t forget to change “andreyexuser” and “192.168.12.054” to the username and IP address of the CentOS 8 server.
Enter “Yes” and click “Enter”.
Enter the password for the username displayed in the terminal and click “Enter”.
The key pair will be copied to the CentOS 8 server, to which we are going to connect.
Step 4: Connect to your CentOS 8 server via SSH
Now, just SSH into your CentOS 8 server using the following command:
$ ssh [email protected]
This is it! We have successfully logged into the CentOS 8 server from a CentOS 8 client machine using SSH.
We have covered the huge spectrum of enabling SSH in CentOS 8 by setting up an OpenSSH server on a CentOS 8 Server machine, enabling the “sshd” service and opening the system firewall for incoming SSH traffic on port 22. We also learned to connect to a CentOS 8 server from a client machine CentOS 8 by installing OpenSSH clients, generating and copying an SSH key pair, copying the key pair to the server machine, and connecting to the CentOS 8 server via SSH.