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.
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.
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 startTo check if ssh port 22 is opened, execute;
# netstat -tulpn | grep :22To set the Firewall:
Modify the IPv4 firewall in the iptables file "/etc/sysconfig/iptables";
# vi /etc/sysconfig/iptablesFor example, add the following lines to the file;
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPTIf 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 ACCEPTAfter adding the necessary data, you can proceed with Saving and closing the file.
To do this, execute;
# service iptables restartFor CentOS 7.x/8.x and above:
Enable and start the sshd service:
# systemctl enable sshd.service# systemctl start sshd.serviceThen 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 --reloadYou can start by editing the /etc/ssh/sshd_config file. To do this, run the command below;
# vi /etc/ssh/sshd_configTo disable root logins, edit or add as shown below:
PermitRootLogin noYou can restrict login to user :'bob' and 'peter' only over ssh:
AllowUsers bob peterTo Change ssh port i.e. run it on a non-standard port like 1235, enter;
Port 1235After 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 ##Here, You can use the ssh command/scp command or sftp command as follows:
ssh user@your-server-ipsftp user.your-server-ip