{"id":6545,"date":"2014-03-18T17:59:30","date_gmt":"2014-03-18T17:59:30","guid":{"rendered":"https:\/\/noi3.org\/site\/?p=6545"},"modified":"2014-03-18T17:59:30","modified_gmt":"2014-03-18T17:59:30","slug":"how-to-secure-ssh-with-google-authenticator-s-two-factor-authentication","status":"publish","type":"post","link":"https:\/\/site.noi3.org\/?p=6545","title":{"rendered":"How to Secure SSH with Google Authenticator\u2019s Two-Factor Authentication"},"content":{"rendered":"<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6537\" alt=\"google-authenticator-ssh-header\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header.png\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px none; width: 250px; height: 96px;\" title=\"google-authenticator-ssh-header\" width=\"650\" height=\"250\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header.png 650w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header-300x115.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p> \tWant to secure your SSH server with easy-to-use two-factor authentication? Google provides the necessary software to integrate Google Authenticator\u2019s time-based one-time password (TOTP) system with your SSH server. You\u2019ll have to enter the code from your phone when you connect.<\/p>\n<p>  <!--more-->  <\/p>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6537\" alt=\"google-authenticator-ssh-header\" border=\"0\" height=\"250\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header.png\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"google-authenticator-ssh-header\" width=\"650\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header.png 650w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header-300x115.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p> \tWant to secure your SSH server with easy-to-use two-factor authentication? Google provides the necessary software to integrate Google Authenticator\u2019s time-based one-time password (TOTP) system with your SSH server. You\u2019ll have to enter the code from your phone when you connect.<\/p>\n<p> \tGoogle Authenticator doesn\u2019t \u201cphone home\u201d to Google \u2014 all the work happens on your SSH server and your phone. In fact, Google Authenticator is <a href=\"http:\/\/code.google.com\/p\/google-authenticator\/\">completely open-source<\/a>, so you can even examine its source code yourself.<\/p>\n<h3> \tInstall Google Authenticator<\/h3>\n<p> \tTo implement multifactor authentication with Google Authenticator, we\u2019ll need the open-source Google Authenticator PAM module. PAM stands for \u201cpluggable authentication module\u201d \u2013 it\u2019s a way to easily plug different forms of authentication into a Linux system.<\/p>\n<p> \tUbuntu\u2019s software repositories contain an easy-to-install package for the Google Authenticator PAM module. If your Linux distribution doesn\u2019t contain a package for this, you\u2019ll have to download it from the <a href=\"https:\/\/code.google.com\/p\/google-authenticator\/downloads\/list\">Google Authenticator downloads page<\/a> on Google Code and compile it yourself.<\/p>\n<p> \tTo install the package on Ubuntu, run the following command:<\/p>\n<blockquote>\n<p> \t\tsudo apt-get install libpam-google-authenticator<\/p>\n<\/blockquote>\n<p> \t(This will only install the PAM module on our system \u2013 we\u2019ll have to activate it for SSH logins manually.)<\/p>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6538\" alt=\"\" border=\"\" class=\"lazyLoad\" height=\"147\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/image163.png\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px none;\" title=\"image\" width=\"650\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image163.png 650w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image163-300x68.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<h3> \tCreate an Authentication Key<\/h3>\n<p> \tLog in as the user you\u2019ll be logging in with remotely and run the <strong>google-authenticator <\/strong>command to create a secret key for that user.<\/p>\n<p> \tAllow the command to update your Google Authenticator file by typing y. You\u2019ll then be prompted with several questions that will allow you to restrict uses of the same temporary security token, increase the time window that tokens can be used for, and limit allowed acces attempts to hinder brute-force cracking attempts. These choices all trade some security for some ease-of-use.<\/p>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6539\" alt=\"\" border=\"\" class=\"lazyLoad\" height=\"248\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/image164.png\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px none;\" title=\"image\" width=\"650\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image164.png 650w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image164-300x114.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p> \tGoogle Authenticator will present you with a secret key and several \u201cemergency scratch codes.\u201d Write down the emergency scratch codes somewhere safe \u2013 they can only be used one time each, and they\u2019re intended for use if you lose your phone.<\/p>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6540\" alt=\"\" border=\"\" class=\"lazyLoad\" height=\"248\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/image165.png\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px none;\" title=\"image\" width=\"650\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image165.png 650w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image165-300x114.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p> \tEnter the secret key in the Google Authenticator app on your phone (official apps are available for <a href=\"http:\/\/support.google.com\/accounts\/bin\/answer.py?hl=en&amp;answer=1066447\">Android, iOS, and Blackberry<\/a>). You can also use the scan barcode feature \u2013 go to the URL located near the top of the command\u2019s output and you can scan a QR code with your phone\u2019s camera.<\/p>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6541\" alt=\"\" border=\"\" class=\"lazyLoad\" height=\"457\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/image166.png\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px none;\" title=\"image\" width=\"288\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image166.png 288w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image166-189x300.png 189w\" sizes=\"auto, (max-width: 288px) 100vw, 288px\" \/><\/p>\n<p> \tYou\u2019ll now have a constantly changing verification code on your phone.<\/p>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6542\" alt=\"\" border=\"\" class=\"lazyLoad\" height=\"260\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/image167.png\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px none;\" title=\"image\" width=\"288\" \/><\/p>\n<p> \tIf you want to log in remotely as multiple users, run this command for each user. Each user will have their own secret key and their own codes.<\/p>\n<h3> \tActivate Google Authenticator<\/h3>\n<p> \tNext you\u2019ll have to require Google Authenticator for SSH logins. To do so, open the <strong>\/etc\/pam.d\/sshd <\/strong>file on your system (for example, with the<strong> sudo nano \/etc\/pam.d\/sshd<\/strong> command) and add the following line to the file:<\/p>\n<blockquote>\n<p> \t\tauth required pam_google_authenticator.so<\/p>\n<\/blockquote>\n<p> \tNext, open the <strong>\/etc\/ssh\/sshd_config<\/strong> file, locate the <strong>ChallengeResponseAuthentication<\/strong> line, and change it to read as follows:<\/p>\n<blockquote>\n<p> \t\tChallengeResponseAuthentication yes<\/p>\n<\/blockquote>\n<p> \t(If the <strong>ChallengeResponseAuthentication<\/strong> line doesn\u2019t already exist, add the above line to the file.)<\/p>\n<p> \tFinally, restart the SSH server so your changes will take effect:<\/p>\n<blockquote>\n<p> \t\tsudo service ssh restart<\/p>\n<\/blockquote>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6543\" alt=\"\" border=\"\" class=\"lazyLoad\" height=\"141\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/image168.png\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px none;\" title=\"image\" width=\"650\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image168.png 650w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/image168-300x65.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p> \tYou\u2019ll be prompted for both your password and Google Authenticator code whenever you attempt to log in via SSH.<\/p>\n<p> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6544\" alt=\"\" border=\"\" class=\"lazyLoad\" height=\"250\" src=\"https:\/\/noi3.org\/site\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header1.png\" style=\"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px none;\" title=\"google-authenticator-ssh-header\" width=\"650\" srcset=\"https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header1.png 650w, https:\/\/site.noi3.org\/wp-content\/uploads\/2014\/03\/google-authenticator-ssh-header1-300x115.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<div style=\"margin-top:0px;margin-bottom:10px;\">\n<hr \/>\n<p> \t\t<a href=\"http:\/\/www.howtogeek.com\/121650\/how-to-secure-ssh-with-google-authenticators-two-factor-authentication\/\">Articolul original<\/a><\/p>\n<hr \/>\n<p> \t\t\u00a0<\/p>\n<\/p><\/div>\n<p> \t\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to secure your SSH server with easy-to-use two-factor authentication? Google provides the necessary software to integrate Google Authenticator\u2019s time-based one-time password (TOTP) system with&hellip;<\/p>\n","protected":false},"author":2,"featured_media":6537,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[1311,457,1310,248],"class_list":["post-6545","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-informatica","tag-cod","tag-google","tag-ssh","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts\/6545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6545"}],"version-history":[{"count":0,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts\/6545\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/media\/6537"}],"wp:attachment":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}