CentOS SSH Installation And Configuration

ADVERTISEMENTS



CentOS SSH Installation

How do I install and configure ssh server and client under CentOS Linux operating systems? Can you explains CentOS SSH installation commands?OpenSSH is a free and open source software for remote login and running commands on CentOS enterprise Linux server or desktop systems. In this tutorial, we will learn how to install ssh server/client and configure the same.

You need to install the following packages (which are installed by default until and unless you removed it or skipped it while installing CentOS):

openssh-clients : The OpenSSH client applications

openssh-server : The OpenSSH server daemon

Let us see all steps in details.

OpenSSH Installations under CentOS Linux

To install the server and client type the following command as root user:

# yum -y install openssh-server openssh-clients



CentOS 6.x and older commands

Start the service:

# chkconfig sshd on

# service sshd start

Make sure port 22 is opened:

# netstat -tulpn | grep :22

Firewall Settings For CentOS 6.x and older

Edit /etc/sysconfig/iptables (IPv4 firewall),

# vi /etc/sysconfig/iptables

Add the lines:

Replace RH-Firewall-1-INPUT with actual chains in your config file. See CentOS/Redhat (RHEL 6.x) tutorial page for more info.

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

If you want to restict access to 192.168.1.0/24, edit it as follows:

-A RH-Firewall-1-INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT

If your site uses IPv6, and you are editing ip6tables, use the line:

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 22 -j ACCEPT

Save and close the file. Restart iptables:

# service iptables restart

CentOS 7.x/8.x and above commands

Enable and start the sshd service:

# systemctl enable sshd.service

# systemctl start sshd.service

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'

OR

ss -tulpn | grep ':22'

Open tcp port 22 using the firewall-cmd command # firewall-cmd --zone=public --add-service=ssh --permanent

# firewall-cmd --reload

OpenSSH Server Configuration

Edit /etc/ssh/sshd_config, enter:

# vi /etc/ssh/sshd_config

To disable root logins, edit or add as follows:

PermitRootLogin no

Restrict login to user tom and jerry only over ssh:

AllowUsers tom jerry

Change ssh port i.e. run it on a non-standard port like 1235

Port 1235

Save and close the file. Restart sshd:

# service sshd restart ## centos 6.x ##

OR

# systemctl restart sshd.service ## centos 7.x/8.x ##

How to test ssh installation

Use the ssh command/scp command or sftp command as follows:

ssh user@your-server-ip

ssh vivek@server1.cyberciti.biz

ssh vivek@server1.cyberciti.biz uptime

sftp server1.cyberciti.biz

scp foo.gif vivek@ln.cbz01:/home/httpd/images

Conclusion

You learned how to install openssh server (sshd) and clients on CentOS Linux using the yum command. For more information please see the following tutorial: