{"id":1815,"date":"2022-05-24T11:21:53","date_gmt":"2022-05-24T09:21:53","guid":{"rendered":"https:\/\/www.dsecbypass.com\/?p=1815"},"modified":"2022-09-27T08:28:44","modified_gmt":"2022-09-27T06:28:44","slug":"how-to-secure-ssh","status":"publish","type":"post","link":"https:\/\/www.dsecbypass.com\/en\/how-to-secure-ssh\/","title":{"rendered":"How to secure SSH?"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;0px||||false|false&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_image src=&#8221;https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2022\/05\/ssh_landscape_lyon.png&#8221; alt=&#8221;SSH landscape Lyon&#8221; title_text=&#8221;ssh_landscape_lyon&#8221; _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; width=&#8221;50%&#8221; module_alignment=&#8221;center&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p style=\"text-align: justify;\">The SSH remote access service allows remote administration of servers, PCs or network equipment. It is available on both Linux and MAC OS as well as Windows. It allows easy and remote access to equipment, with the privileges of the chosen user.<\/p>\n<p style=\"text-align: justify;\">We will then speak of an <strong>SSH server<\/strong>, on which the user, the <strong>SSH client,<\/strong> connects.<\/p>\n<p style=\"text-align: justify;\">Often exposed on the Internet, it is necessary to follow some <strong>SSH security best practices<\/strong> in order to reduce the risks.<\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h2 class=\"part\" data-startline=\"14\" data-endline=\"14\"> What are the risks?<\/h2>\n<p>Several risks exist on an exposed SSH service:<\/p>\n<ul>\n<li><strong>Weak passwords<\/strong> : unauthorized access through password enumeration attack (<em>bruteforce<\/em>) ;<\/li>\n<li><strong>Compromised account<\/strong> : unauthorized access through stolen account (password reuse or <em>keylogger<\/em>) ;<\/li>\n<li><strong>Interception of communications<\/strong>: attacker in a <em>Man-in-The-Middle<\/em> position, for example on a public Wi-Fi;<\/li>\n<li><strong>Loss of access<\/strong>: single access account blocked;<\/li>\n<li><strong>Information leaks<\/strong>: obtaining the OS and its version in the service banner;<\/li>\n<li><strong>Privilege escalation<\/strong>: Stealing SSH sessions from other users;<\/li>\n<li><strong>Vulnerable service<\/strong>: exploitation of a vulnerability on an outdated SSH server.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Once the service is compromised, attackers will very often deploy a cryptocurrency miner, deface the website or resell access to the server in a network of <em>botnets<\/em>.<\/p>\n<p style=\"text-align: justify;\">In some cases, the attack can be targeted and give access to the company&#8217;s internal network. The hacker will then favor a <em>ransomware<\/em> attack, data theft or a scam to the president.<\/p>\n<p>&nbsp;<\/p>\n<h2>Check the security level of your SSH access<\/h2>\n<p style=\"text-align: justify;\">An <a href=\"https:\/\/www.dsecbypass.com\/en\/external-pentest\/\">external penetration test<\/a>ensures that it is not possible for an attacker to exploit the SSH service.<\/p>\n<p style=\"text-align: justify;\">In the cas of a jump hostor a <em>bastion<\/em>, it is advised to perform <strong>a whitebox pentest assessment<\/strong> (access to different account levels and to the configuration) in order to test, for example, partitioning between accounts, bypassing network filtering from the SSH server and service configuration.<\/p>\n<p style=\"text-align: justify;\">In order to audit itself the hardening of the algorithms of its SSH services, the Linux tool <strong>ssh-audit<\/strong> (<a href=\"https:\/\/github.com\/jtesta\/ssh-audit\">https:\/\/github.com\/jtesta\/ssh-audit<\/a>) can be used.<\/p>\n<p>To install it on Kali Linux:<\/p>\n<blockquote>\n<p>sudo apt install ssh-audit<\/p>\n<p>ssh-audit -p PORT @IP<\/p>\n<\/blockquote>\n<p style=\"text-align: justify;\">For example: ssh-audit -p 2222 127.0.0.1 will test the hardening of the algorithms and report potential CVEs on the server version.<\/p>\n<p style=\"text-align: justify;\">For an audit of the SSH server configuration itself, the Linux <strong>Lynis<\/strong>tool (<a href=\"https:\/\/github.com\/CISOfy\/lynis\">https:\/\/github.com\/CISOfy\/lynis<\/a>) includes SSH checks to increase the level of security. Its use is described in the official documentation: <a href=\"https:\/\/cisofy.com\/documentation\/lynis\/get-started\/#installation-git\">https:\/\/cisofy.com\/documentation\/lynis\/get-started\/#installation-git<\/a>. It is therefore sufficient to run Lynis on the SSH server in order to detect potential weaknesses in its configuration.<\/p>\n<p>&nbsp;<\/p>\n<h2>SSH security best practices<\/h2>\n<p>SSH server configuration resides in Linux file <em>\/etc\/ssh\/sshd_config<\/em> and Windows <em><span class=\"ILfuVd\"><span class=\"hgKElc\">%programdata%\\ssh\\sshd_config<\/span><\/span><\/em>.<\/p>\n<p>The following principles and configuration points can be used to enhance the security of the SSH service:<\/p>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Favor <strong>SSH key based authentication<\/strong> rather than by password<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"color: #008000;\">PubkeyAuthentication yes<\/span><\/li>\n<li><span style=\"color: #008000;\">PasswordAuthentication no<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Protect your <em>SSH key<\/em> with a <strong>complex passphrase<\/strong><\/p>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Do not accept <strong>empty passwords<\/strong><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"color: #008000;\">PermitEmptyPasswords no<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Limit the number of invalid authentications<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"color: #008000;\">MaxAuthTries 3<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Secure root account<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"color: #008000;\">PermitRootLogin no<\/span><\/li>\n<li><span style=\"color: #008000;\">PermitRootLogin without-password<\/span> (allow root login with an SSH key)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Complement this limit with a system to <strong>ban IPs<\/strong> that attack the service<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><a href=\"https:\/\/doc.ubuntu-fr.org\/fail2ban\">https:\/\/doc.ubuntu-fr.org\/fail2ban<\/a><\/li>\n<li>Other security solutions (SIEM, SOAR, IPS)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f If possible, create a whitelist of <strong>Linux groups or users<\/strong> authorized to connect in SSH:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"color: #008000;\">AllowGroups <em>groupname<\/em><\/span><\/li>\n<li><span style=\"color: #008000;\">AllowUsers <em>justin sammy vladimir<\/em><\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u2714\ufe0f <strong>Reduce information leaks<\/strong> in the file known_hosts :<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"color: #008000;\">HashKnownHosts yes<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f <strong>Reduce information leaks<\/strong> from the SSH service banner:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li class=\"LC20lb MBeuO DKV0Md\"><span style=\"color: #008000;\">DebianBanner no<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f <strong>Change the default listening port<\/strong> (22) to a non-standard port (and not 2222 either) in order to decrease the &#8220;noise&#8221; generated by scanners on the Internet<\/p>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Protect SSH access <strong>with VPN access or restricting the IP addresses<\/strong> you and your providers use when possible<\/p>\n<p class=\"LC20lb MBeuO DKV0Md\">\u2714\ufe0f Consider a &#8220;<em>jumphost<\/em>&#8221; architecture when a large number of SSH services must be accessible<\/p>\n<p style=\"text-align: justify;\">For correspondences with the OpenSSH configuration under Windows, see the official documentation: <a href=\"https:\/\/docs.microsoft.com\/fr-fr\/windows-server\/administration\/openssh\/openssh_server_configuration\">https:\/\/docs.microsoft.com\/fr-fr\/windows-server\/administration\/openssh\/openssh_server_configuration<\/a>.<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-decoration: underline;\">Note:<\/span> these recommendations should be applied according to your needs and your environment, after ensuring that they do not impact access to services.<\/p>\n<p style=\"text-align: justify;\">References: <a href=\"https:\/\/www.ssi.gouv.fr\/administration\/guide\/recommandations-pour-un-usage-securise-dopenssh\/%7C\">https:\/\/www.ssi.gouv.fr\/administration\/guide\/recommandations-pour-un-usage-securise-dopenssh<\/a> | <a href=\"https:\/\/www.ssh-audit.com\/hardening_guides.html\">https:\/\/www.ssh-audit.com\/hardening_guides.html<\/a> | <a href=\"https:\/\/linux-audit.com\/audit-and-harden-your-ssh-configuration\/\">https:\/\/linux-audit.com\/audit-and-harden-your-ssh-configuration\/<\/a><\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p style=\"text-align: justify;\"><span>\ud83d\udee1\ufe0f DSecBypass supports you in securing your SSH services during <a href=\"https:\/\/www.dsecbypass.com\/en\/external-pentest\/\">external pentests<\/a> or <a href=\"https:\/\/www.dsecbypass.com\/en\/internal-pentest\/\">internal security audits<\/a>, with quality services and significant experience in this type of service. Do not hesitate to <a href=\"https:\/\/www.dsecbypass.com\/en\/dsecbypass-contact-cybersecurity-company-lyon\/\">contact <\/a>us for additional information and\/or a personalized quote \ud83d\udcdd.<\/span><\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_button button_url=&#8221;https:\/\/www.dsecbypass.com\/en\/contact\/&#8221; button_text=&#8221;CONTACT US&#8221; button_alignment=&#8221;center&#8221; _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; custom_button=&#8221;on&#8221; button_text_size=&#8221;13px&#8221; button_bg_color=&#8221;#4328b7&#8243; button_border_width=&#8221;10px&#8221; button_border_color=&#8221;#4328b7&#8243; button_border_radius=&#8221;0px&#8221; button_letter_spacing=&#8221;2px&#8221; button_font=&#8221;Titillium Web|700||on|||||&#8221; background_layout=&#8221;dark&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_button][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SSH remote access service allows remote administration of servers, PCs or network equipment. It is available on both Linux and MAC OS as well as Windows. It allows easy and remote access to equipment, with the privileges of the chosen user.<\/p>\n<p>We will then speak of an SSH server, on which the user, the SSH client, connects.<\/p>\n<p>Often exposed on the Internet, it is necessary to follow some SSH security best practices in order to reduce the risks.<\/p>\n","protected":false},"author":4,"featured_media":1677,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-1815","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en"],"_links":{"self":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/1815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/comments?post=1815"}],"version-history":[{"count":9,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/1815\/revisions"}],"predecessor-version":[{"id":2473,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/1815\/revisions\/2473"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/media\/1677"}],"wp:attachment":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/media?parent=1815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/categories?post=1815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/tags?post=1815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}