How to Install SSH on CentOS server

In this article, we will look into the step-by-step methods on How to Install SSH on CentOS server, configuration, and common errors.

A) How to install SSH on a server?

B) How can we check SSH service is running?

C) How to change the SSH listening port?

D) Some common errors you may encounter with ssh?

A) How to install SSH on a server?

1. If ssh is not installed on your server then you need to login through the VNC.

2. Once you logged into the server then please check the below command to install SSH:

Installing ssh

# yum install openssh openssh-server openssh-clients openssl-libs

Once this is done you are free to connect to the server

The default configuration path of ssh is:

#/etc/ssh/sshd_config

Almost all the settings are made in this file.

Note: Before making any changes please take a copy of the file

Also read : Advantages and Disadvantages of Linux over windows and other operating systems

B) How can we check SSH service is running?

Once you are on the server please check the below commands to find whether the ssh is running and to find the port that ssh is using:

# service sshd status

Output:(If the ssh is running

sshd.service – OpenSSH server daemon

Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)

Active: active (running) since Fri 2017-02-03 05:23:58 EST; 5min ag

If you get this, that means the service is running. You can run the below command to make sure about the service.

#netstat -plant | grep sshd

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 17268/sshd

netstat command clearly shows that the server is using ssh service and 22 is the listing port

C) How to change the SSH listening port?

Please open the configuration file of SSH by using an editor (such as “vim, nano”):

# vim /etc/ssh/sshd_config

Change the PORT=22 to any other port you like (please uncommand the # symbol). You can see the port number mentioned at the top when you open /etc/ssh/sshd_config. Change default ssh port. Once you have done this step restart the sshd

#service sshd restart

Please note that you need to allow open the port in Iptables as well

# iptables -A INPUT -p tcp –dport 1243 -j ACCEPT

Check whether the selinux allow the port

#semanage port -l | grep 22

If it gives output as below then the new port you have provided is not allowed by selinux

# ssh_port_t tcp 22

You can run the below command to allow the selinux for a port

# semanage port -a -t ssh_port_t -p tcp <port for ssh>

Once you have done all these you can logout and try ssh with the new port

D) Some common errors you may encounter with ssh?

Error 1: SSH: Permission denied (publickey,gssapi-with-mic,password)

This means that ssh via clear text is not enabled in ssh. Please follow the below steps:

# vim /etc/ssh/sshd_config

Change the “PasswordAuthentication = yes” in the file

Once it is done please save and restart the sshd

# service sshd restart

Leave a Comment