{"id":27,"date":"2023-12-04T11:51:28","date_gmt":"2023-12-04T18:51:28","guid":{"rendered":"https:\/\/www.7softinteractive.net\/?p=27"},"modified":"2023-12-05T10:56:49","modified_gmt":"2023-12-05T17:56:49","slug":"linux-ssh","status":"publish","type":"post","link":"https:\/\/www.7softinteractive.net\/?p=27","title":{"rendered":"SSH"},"content":{"rendered":"\n<p>OpenSSH Configuration and Setup, basic procedure to setup and secure an SSH Server on Linux.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><br># 1. Installing OpenSSH (client and server)<br># Ubuntu<br>sudo apt update &amp;&amp; sudo apt install openssh-server openssh-client<br> <br># CentOS<br>sudo dnf install openssh-server openssh-clients<br> <br># connecting to the server<br>ssh -p 22 username@server_ip        # => Ex: ssh -p 2267 john@192.168.0.100<br>ssh -p 22 -l username server_ip<br>ssh -v -p 22 username@server_ip     # => verbose<br> <br># 2. Controlling the SSHd daemon<br># checking its status<br>sudo systemctl status ssh       # => Ubuntu<br>sudo systemctl status sshd      # => CentOS<br> <br># stopping the daemon<br>sudo systemctl stop ssh       # => Ubuntu<br>sudo systemctl stop sshd      # => CentOS<br> <br># restarting the daemon<br>sudo systemctl restart ssh       # => Ubuntu<br>sudo systemctl restart sshd      # => CentOS<br> <br># enabling at boot time <br>sudo systemctl enable ssh       # => Ubuntu<br>sudo systemctl enable sshd      # => CentOS<br> <br>sudo systemctl is-enabled ssh       # => Ubuntu<br>sudo systemctl is-enabled sshd      # => CentOS<br> <br># 3. Securing the SSHd daemon<br># change the configuration file (\/etc\/ssh\/sshd_config) and then restart the server<br>man sshd_config<br> <br>a) Change the port<br>Port 2278<br> <br>b) Disable direct root login<br>PermitRootLogin no<br> <br>c) Limit Users\u2019 SSH access<br>AllowUsers stud u1 u2 john<br> <br>d) Filter SSH access at the firewall level (iptables)<br> <br>e) Activate Public Key Authentication and Disable Password Authentication<br> <br>f) Use only SSH Protocol version 2<br> <br>g) Other configurations:<br>ClientAliveInterval 300<br>ClientAliveCountMax 0<br>MaxAuthTries 2<br>MaxStartUps 3<br>LoginGraceTime 20<br><br>** Commands &#8211; Locking User Accounts<br># locking password authentication<br>sudo passwd -l USERNAME<br>sudo password &#8211;lock USERNAME<br> <br># checking the account status<br>sudo passwd &#8211;status USERNAME<br>sudo chage -l USERNAME<br> <br># unlocking password authentication<br>sudo passwd -u USERNAME<br> <br># disable an account completely<br>sudo usermod &#8211;expiredate 1 tux<br>sudo usermod &#8211;expiredate 1970-01-02 tux<br> <br># checking the account expiration date<br>sudo chage -l tux<br><br><br><br><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenSSH Configuration and Setup, basic procedure to setup and secure an SSH Server on Linux.<\/p>\n","protected":false},"author":1,"featured_media":12,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-27","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":11,"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions\/127"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=\/wp\/v2\/media\/12"}],"wp:attachment":[{"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.7softinteractive.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}