{"id":351,"date":"2019-05-12T14:42:59","date_gmt":"2019-05-12T12:42:59","guid":{"rendered":"http:\/\/hentati.org\/?p=351"},"modified":"2020-12-06T21:20:58","modified_gmt":"2020-12-06T20:20:58","slug":"centos-rhel-install-and-configure-openssh-server-and-client","status":"publish","type":"post","link":"https:\/\/hentati.org\/index.php\/2019\/05\/12\/centos-rhel-install-and-configure-openssh-server-and-client\/","title":{"rendered":"CentOS \/ RHEL : Install and Configure OpenSSH Server and Client"},"content":{"rendered":"<div>\n<h5><span style=\"color: #000000;\">Introduction<\/span><\/h5>\n<p><span style=\"color: #000000;\">OpenSSH (Secure Shell) is a suite of network connectivity tools that provides secure communications between systems. OpenSSH tools include the following:<\/span><\/p>\n<\/div>\n<ul>\n<li><span style=\"color: #000000;\"><strong>ssh<\/strong>: Secure shell logs on or runs a command on a remote system<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>scp<\/strong>: Secure copy<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>sftp<\/strong>: Secure ftp (file transfer protocol)<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>sshd<\/strong>: The OpenSSH daemon<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>ssh-keygen<\/strong>: Creates ECDSA(Elliptic Curve Digital Signature Algorithm) or RSA(named for the designers Rivest, Shamir, and Adleman) host\/user authentication keys:<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #000000;\">Unlike other tools such as\u00a0<strong>telnet, rcp, rsh, rlogin,<\/strong>\u00a0and\u00a0<strong>ftp<\/strong>, OpenSSH tools encrypt all communication between the client and server systems, including passwords. Each network packet is encrypted by using a key known only by the local and remote systems.<\/span><\/p>\n<p><span style=\"color: #000000;\">OpenSSH supports both versions of SSH, SSH protocol version 1 (SSH1) and SSH protocol version 2 (SSH2). Additionally, OpenSSH provides a secure means to use graphical applications over a network by using X11 forwarding. It also provides a way to secure otherwise insecure TCP\/IP protocols by using port forwarding.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h5><span style=\"color: #000000;\">I- install OpenSSH Server<\/span><\/h5>\n<p><span style=\"color: #000000;\">1. To begin configuring a system as an OpenSSH server, install the following packages (these are installed by default):<\/span><\/p>\n<div class=\"codeme\">\n<pre><span style=\"color: #000000;\"># yum install openssh\r\n# yum install openssh-server<\/span><\/pre>\n<\/div>\n<p><span style=\"color: #000000;\">2. Start the sshd daemon:<\/span><\/p>\n<div class=\"codeme\">\n<pre><span style=\"color: #000000;\"># systemctl start sshd<\/span><\/pre>\n<\/div>\n<p><span style=\"color: #000000;\">3. Use the systemctl command to automatically start the sshd service at boot time:<\/span><\/p>\n<div class=\"codeme\">\n<pre><span style=\"color: #000000;\"># systemctl enable sshd<\/span><\/pre>\n<\/div>\n<div class=\"heading-text el-text\">\n<h5><span style=\"color: #000000;\">II- Configure OpenSSH Server<\/span><\/h5>\n<\/div>\n<div class=\"uncode_text_column\">\n<div class=\"clear\"><span style=\"color: #000000;\">Properly configuring the\u00a0<strong>sshd<\/strong>\u00a0configuration file\u00a0hardens server security. The most common settings to enhance security are changing the port number, disabling root logins, and limiting access to only certain users.<\/span><\/div>\n<div class=\"uncode_text_column\">\n<p><span style=\"color: #000000;\">To edit these settings access the \/<strong>etc\/ssh\/sshd_config<\/strong>\u00a0file:<\/span><\/p>\n<pre class=\"chroma\"><span style=\"color: #000000;\"><code class=\"language-output\" data-lang=\"output\">sudo vim \/etc\/ssh\/sshd_config<\/code><\/span><\/pre>\n<p><span style=\"color: #000000;\">Once you access the file by using a text editor (in this example we used\u00a0<strong>vim<\/strong>), you can disable root logins and edit the default port number:<\/span><\/p>\n<ul>\n<li><span style=\"color: #000000;\">To disable root login:<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #000000;\"><strong><em>PermitRootLogin no<\/em><\/strong><\/span><\/p>\n<ul>\n<li><span style=\"color: #000000;\">Change the SSH port to run on a non-standard port. For example:<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #000000;\"><strong><em>Port 2002<\/em><\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\"><img loading=\"lazy\" class=\"aligncenter wp-image-81699 size-full lazyloaded\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2019\/08\/port-root-login-settings.png\" alt=\"Settings in sshd config file of port 2002\" width=\"800\" height=\"403\" data-lazy-src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2019\/08\/port-root-login-settings.png\" data-was-processed=\"true\" \/><\/span><\/p>\n<p><span style=\"color: #000000;\">Remember to uncomment the lines that you edit by removing the hashtag.<\/span><\/p>\n<p><span style=\"color: #000000;\">Save and close the file. Restart\u00a0<strong>sshd<\/strong>:<\/span><\/p>\n<pre class=\"chroma\"><span style=\"color: #000000;\"><code class=\"language-output\" data-lang=\"output\">service sshd restart<\/code><\/span><\/pre>\n<\/div>\n<div class=\"heading-text el-text\">\n<h4><span style=\"color: #000000;\">\u00a0<\/span><\/h4>\n<h5><span style=\"color: #000000;\">FIREWALL SETTINGS<\/span><\/h5>\n<\/div>\n<div class=\"uncode_text_column\">\n<p><span style=\"color: #000000;\">After successfully enabling SSH and configuring the\u00a0<strong>sshd<\/strong>\u00a0file, adjust the firewall settings to make sure there are no compatibility issues.<\/span><\/p>\n<p><span style=\"color: #000000;\">It is also possible to restrict IP access to make the connection even more secure.<\/span><\/p>\n<p><span style=\"color: #000000;\">To restrict IP access, edit the\u00a0<strong>iptables<\/strong>\u00a0file by typing:<\/span><\/p>\n<pre class=\"chroma\"><span style=\"color: #000000;\"><code class=\"language-output\" data-lang=\"output\">sudo vim \/etc\/sysconfig\/iptables<\/code><\/span><\/pre>\n<p><span style=\"color: #000000;\">To allow access using the port defined in the sshd config file, add the following line to the iptables file:<\/span><\/p>\n<pre class=\"chroma\"><span style=\"color: #000000;\"><code class=\"language-output\" data-lang=\"output\">-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 2002 -j ACCEPT<\/code><\/span><\/pre>\n<p><span style=\"color: #000000;\">To restrict access to a specific IP, for example 133.123.40.166, edit the line as follows:<\/span><\/p>\n<pre class=\"chroma\"><span style=\"color: #000000;\"><code class=\"language-output\" data-lang=\"output\">-A RH-Firewall-1-INPUT -s 133.123.40.166 -m state --state NEW -p tcp --dport 2002 -j ACCEPT<\/code><\/span><\/pre>\n<p><span style=\"color: #000000;\"><img loading=\"lazy\" class=\"aligncenter wp-image-81700 size-full lazyloaded\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2019\/08\/set-firewall-rules-centos-sshd-server.png\" alt=\"example of setting up firewall rules\" width=\"800\" height=\"255\" data-lazy-src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2019\/08\/set-firewall-rules-centos-sshd-server.png\" data-was-processed=\"true\" \/><\/span><\/p>\n<p><span style=\"color: #000000;\">If your site uses IPv6, and you are editing ip6tables, use the line:<\/span><\/p>\n<pre class=\"chroma\"><span style=\"color: #000000;\"><code class=\"language-output\" data-lang=\"output\">-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 2002 -j ACCEPT<\/code><\/span><\/pre>\n<p><span style=\"color: #000000;\">Save and exit the file by pressing Escape (Esc) on your keyboard and typing:<\/span><\/p>\n<pre><span style=\"color: #000000;\"><strong>:X<\/strong><\/span><\/pre>\n<p><span style=\"color: #000000;\">Press Enter to confirm.<\/span><\/p>\n<p><span style=\"color: #000000;\">Restart iptables to apply the changes:<\/span><\/p>\n<pre class=\"chroma\"><span style=\"color: #000000;\"><code class=\"language-output\" data-lang=\"output\">sudo systemctl restart iptables<\/code><\/span><\/pre>\n<\/div>\n<div class=\"heading-text el-text\">\n<p>&nbsp;<\/p>\n<h5><span style=\"color: #000000;\">iii- ConfigurE OpenSSH Client<\/span><\/h5>\n<p><span style=\"color: #000000;\">1. To configure a system as an OpenSSH client, install the following packages (these are installed by default):<\/span><\/p>\n<div class=\"codeme\">\n<pre><span style=\"color: #000000;\"># yum install openssh\r\n# yum install openssh-clients<\/span><\/pre>\n<\/div>\n<p><span style=\"color: #000000;\">2. There are no services to start for OpenSSH clients.<\/span><\/p>\n<h5><span style=\"color: #000000;\">CONCLUSION<\/span><\/h5>\n<p><span style=\"color: #000000;\">In this tutorial, we learned how to enable SSH on a CentOS 7 server. Additionally, we configured your firewall and SSH rules to limit access.<\/span><\/p>\n<\/div>\n<div class=\"uncode_text_column\">\n<p><span style=\"color: #000000;\">Your CentOS 7 server is now able to accept SSH connections.<\/span><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction OpenSSH (Secure Shell) is a suite of network connectivity tools that provides secure communications between systems. OpenSSH tools include the following: ssh: Secure shell logs on or runs a &#8230;<\/p>\n","protected":false},"author":1,"featured_media":372,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts\/351"}],"collection":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":20,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":657,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions\/657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/media\/372"}],"wp:attachment":[{"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hentati.org\/index.php\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}