Need to install and configure ssh server and client under CentOS Linux operating systems? Do you want to learn SSH installation commands used in CentOS servers?
This guide is for you.
SSH software packages are included on CentOS by default.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Ubuntu related tasks and Software Installations.
In this context, we shall look into the process of Installation And Configuration of SSH on CentOS Servers.
How to install SSH in CentOS ?
You need to install the following packages (which are installed by default until and unless you removed it or skipped it while installing CentOS):
i. openssh-clients : The OpenSSH client applications.
ii. openssh-server : The OpenSSH server daemon.
Now let us see the steps in more details.
How to install OpenSSH in CentOS ?
To install the OpenSSH server and client, execute the following command as the root user using an SSH tool such as putty:
# yum -y install openssh-server openssh-clients
For CentOS 6.x and older versions:
To start the service, execute;
# chkconfig sshd on
# service sshd start
To check if ssh port 22 is opened, execute;
# netstat -tulpn | grep :22
To set the Firewall:
Modify the IPv4 firewall in the iptables file "/etc/sysconfig/iptables";
# vi /etc/sysconfig/iptables
For example, add the following lines to the file;
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
If you are using IPv6, and you are editing ip6tables, then use the line:
-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 22 -j ACCEPT
After adding the necessary data, you can proceed with Saving and closing the file.
To do this, execute;
# service iptables restart
For CentOS 7.x/8.x and above:
Enable and start the sshd service:
# systemctl enable sshd.service
# systemctl start sshd.service
Then verify that TCP port number 22 is in listing state using the ss command/netstat command along with the grep command:
ss -tulpn | grep ':22'
Alternatively, you can use the command:
ss -tulpn | grep ':22'
To open tcp port 22, execute the firewall-cmd command:
# firewall-cmd --zone=public --add-service=ssh --permanent
# firewall-cmd --reload
How to configure OpenSSH Server ?
You can start by editing the /etc/ssh/sshd_config file. To do this, run the command below;
# vi /etc/ssh/sshd_config
To disable root logins, edit or add as shown below:
You can restrict login to user :'bob' and 'peter' only over ssh:
AllowUsers bob peter
To Change ssh port i.e. run it on a non-standard port like 1235, enter;
After saving and closing the file, Restart sshd:
# service sshd restart ## centos 6.x ##
You can also restart sshd by running;
# systemctl restart sshd.service ## centos 7.x/8.x ##
Testing SSH installation on CentOS ?
Here, You can use the ssh command/scp command or sftp command as follows: