In this post, we will go through a step-by-step guide on how to enable SSH on CentOS 8 and access its server from a CentOS 8 client machine while remotely using the SSH. Let’s start with the configuration of the CentOS 8 server for remote connection via SSH.
Configuration of CentOS 8 Server for Remote Connection
Configuring CentOS 8 server for a remote connection is our first priority.
Step 1: Update Your System’s Package Repository
Update the system’s package repository cache by typing the command below:
Upgrade the system’s packages.
Step 2: Install OpenSSH Server on CentOS 8 Server
After updating the system’s repository cache and packages, install the OpenSSH server package by typing the command below:
After successful installation, start the “sshd” service if it is not started.
Step 3: Start OpenSSH Service
For starting the OpenSSH service, type the command below:
Check the status of the service using the command below:
Also, enable OpenSSH service on reboot by typing the command given below:
Alright, the OpenSSH service is active and ready for connection. Now, we need to get the traffic going, and for that, we are required to configure the firewall.
Step 4: Allow the Firewall to Pass any Traffic from SSH port 22
For allowing the firewall for traffic flow through the SSH, type the command below:
It is a better practice to reload the firewall after configuring the firewall.
The CentOS 8 server is ready for connection via SSH. Let’s know 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 the CentOS server, type the command below:
The IP address of my server is 192.168.18.186. Let’s connect to this machine from the client CentOS 8 machine.
Connect to the CentOS 8 Server from CentOS 8 Client
For connecting to the CentOS 8 server, follow the step given below:
Step 1: Install OpenSSH Clients on CentOS 8 Client Machine
First of all, you need to install the OpenSSH Clients on your client CentOS 8 machine.
After installing OpenSSH Clients, create and copy the SSH key pairs for connecting to the CentOS 8 server.
Step 2: Generate the SSH Key Pair
For generating the SSH key pair, type the command given below:
Hit “Enter” to save the key pair in the given default directory.
Or if you have already generated the key pair, hit “Enter” to overwrite the previously generated key pair.
Provide the passphrase or hit “Enter” for the empty passphrase.
Alright, the key pair is generated successfully, now let’s copy the key pair to the server.
Step 3: Copy the Key Pair to the CentOS 8 Server
For copying the key pair to the CentOS 8 server, type the command below:
Do not forget to change the “linuxuser” and “192.168.18.186” with the username and IP address of the CentOS 8 server.
Type “yes” and hit “Enter”.
Provide the password of the username shown in the terminal and hit “Enter”.
The key pair will be copied to the CentOS 8 server, to which we are going to connect.
Step 4: Connect to the CentOS 8 Server via SSH
Now, simply connect SSH into the CentOS 8 server using the command below:
This is it! We are logged in to the CentOS 8 server successfully from a CentOS 8 Client machine using the SSH.
Conclusion
We have covered an enormous spectrum of enabling the SSH on CentOS 8 by installing OpenSSH server on CentOS 8 Server machine, enabling the “sshd” service, and opening the firewall of the system for incoming traffic from SSH on port 22. We have also learned to connect to the CentOS 8 server from a CentOS 8 client machine by installing OpenSSH clients, generating and copying the SSH key pair, copying the keypair to the Server machine, and connecting to the CentOS 8 Server via SSH.