{"id":5748,"date":"2024-03-06T12:23:00","date_gmt":"2024-03-06T18:23:00","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=5748"},"modified":"2024-03-06T09:28:46","modified_gmt":"2024-03-06T15:28:46","slug":"harden-ssh-for-almalinux-9-rhel-fedora","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/harden-ssh-for-almalinux-9-rhel-fedora\/","title":{"rendered":"Harden SSH for AlmaLinux 9 (RHEL, Fedora)"},"content":{"rendered":"\n<p>These steps are taken from the following link.  They have other guides for hardening Ubuntu, Debian etc.  <\/p>\n\n\n\n<p><a href=\"https:\/\/www.sshaudit.com\/hardening_guides.html#rocky9\">https:\/\/www.sshaudit.com\/hardening_guides.html#rocky9<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><em>You will need to become the root user, use either su &#8211; or sudo -i<\/em><\/p>\n\n\n\n<p>First we need to regenerate the RSA and ED25519 keys<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\">rm \/etc\/ssh\/ssh_host_*<br>ssh-keygen -t rsa -b 4096 -f \/etc\/ssh\/ssh_host_rsa_key -N \"\"<br>ssh-keygen -t ed25519 -f \/etc\/ssh\/ssh_host_rsa_key -N \"\"<\/code><\/pre>\n\n\n\n<p>Next, remove the small Diffie-Hellman moduli.  The moduli file contains prime numbers and generators.  Removing the smaller numbers should help increase security as it makes attempting to factor the private keys harder.<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\">awk '$5 >= 3071' \/etc\/ssh\/moduli > \/etc\/ssh\/moduli.safe<br>mv \/etc\/ssh\/moduli.safe \/etc\/ssh\/moduli<\/code><\/pre>\n\n\n\n<p>We can now specify which key exchange, ciphers, and algorithms to use.<\/p>\n\n\n\n<p>Add the following to &#8220;\/etc\/crypto-policies\/back-ends\/opensshserver.config&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\"># Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com\n# hardening guide.\nKexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256\n\nCiphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\n\nMACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com\n\nHostKeyAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\nRequiredRSASize 3072\n\nCASignatureAlgorithms sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\nGSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512-\n\nHostbasedAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-256\n\nPubkeyAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256<\/code><\/pre>\n\n\n\n<p>Finally, restart the ssh server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart sshd<\/pre>\n\n\n\n<p>Other helpful links<\/p>\n\n\n\n<p><a href=\"https:\/\/www.ssh.com\/academy\">https:\/\/www.ssh.com\/academy<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.redhat.com\/en\/blog\/primes-parameters-and-moduli\">https:\/\/www.redhat.com\/en\/blog\/primes-parameters-and-moduli<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/security.stackexchange.com\/questions\/79043\/is-it-considered-worth-it-to-replace-opensshs-moduli-file\">https:\/\/security.stackexchange.com\/questions\/79043\/is-it-considered-worth-it-to-replace-opensshs-moduli-file<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>These steps are taken from the following link. They have other guides for hardening Ubuntu, Debian etc. https:\/\/www.sshaudit.com\/hardening_guides.html#rocky9 You will need to become the root user, use either su &#8211; or sudo -i First we need to regenerate the RSA &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/harden-ssh-for-almalinux-9-rhel-fedora\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1408,3,573],"tags":[1389,17,19,1309,307,7,127,538,1648,1650,221,294],"class_list":["post-5748","post","type-post","status-publish","format-standard","hentry","category-hardening-guides","category-linux","category-security","tag-almalinux","tag-centos","tag-fedora","tag-hardening","tag-keys","tag-linux-2","tag-red-hat","tag-rhel","tag-rocky","tag-rocky-linux","tag-ssh","tag-sshd"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=5748"}],"version-history":[{"count":4,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5748\/revisions"}],"predecessor-version":[{"id":5752,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5748\/revisions\/5752"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=5748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=5748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=5748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}