{"id":2046,"date":"2016-01-16T17:23:28","date_gmt":"2016-01-16T17:23:28","guid":{"rendered":"http:\/\/emtunc.org\/blog\/?p=2046"},"modified":"2017-02-24T15:09:20","modified_gmt":"2017-02-24T15:09:20","slug":"setting-duo-security-ubuntu-server-2fa","status":"publish","type":"post","link":"https:\/\/emtunc.org\/blog\/01\/2016\/setting-duo-security-ubuntu-server-2fa\/","title":{"rendered":"Setting up Duo Security with Ubuntu Server for 2FA"},"content":{"rendered":"<p>In this article I will go through the steps required to install and configure Duo Security with Ubuntu Server for two factor authentication. This can be adapted to apply to SSH log-ons, sudo access, etc. The Linux PAM (pluggable authentication modules) make this easy to implement and customise.<\/p>\n<p>I currently have this implemented on my Ubuntu 14.04 x64 LTS Server and it works really well.<\/p>\n<p><!--more--><\/p>\n<h3>Prerequisites<\/h3>\n<p>We need to add the Duo Security repository to your sources, import the GPG key, refresh the apt-get cache then install the duo-unix package.<br \/>\nNote: Replace\u00a0<em>trusty<\/em> with\u00a0<em>precise<\/em> if you&#8217;re running Ubuntu 12.04<\/p>\n<pre class=\"lang:default decode:true\">echo 'deb http:\/\/pkg.duosecurity.com\/Ubuntu trusty main' | sudo tee \/etc\/apt\/sources.list.d\/duosecurity.list\r\ncurl -s https:\/\/duo.com\/APT-GPG-KEY-DUO | sudo apt-key add -\r\nsudo apt-get update\r\nsudo apt-get install duo-unix<\/pre>\n<p>Now we need to run through a few pages on the Duo website to get the integration keys.<\/p>\n<ol>\n<li>Log-in to the <a href=\"https:\/\/admin.duosecurity.com\/\" target=\"_blank\">Duo Security admin page<\/a><\/li>\n<li>Click Applications &#8211;&gt; Protect an Application<br \/>\n<a href=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_41_06-Applications-Ertugrul-Mikail-Tunc-Duo.png\" rel=\"attachment wp-att-2048\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2048\" src=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_41_06-Applications-Ertugrul-Mikail-Tunc-Duo.png\" alt=\"2016-01-16 12_41_06-Applications - Ertugrul-Mikail Tunc - Duo\" width=\"1379\" height=\"200\" srcset=\"https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_41_06-Applications-Ertugrul-Mikail-Tunc-Duo.png 1379w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_41_06-Applications-Ertugrul-Mikail-Tunc-Duo-300x44.png 300w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_41_06-Applications-Ertugrul-Mikail-Tunc-Duo-768x111.png 768w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_41_06-Applications-Ertugrul-Mikail-Tunc-Duo-1024x149.png 1024w\" sizes=\"auto, (max-width: 1379px) 100vw, 1379px\" \/><br \/>\n<\/a><\/li>\n<li>Scroll down to\u00a0<strong>Unix Application<\/strong> and click\u00a0<strong>Protect this Application<\/strong><\/li>\n<li>Make a note of your integration key, secret key and API hostname.<\/li>\n<\/ol>\n<h3>Configuration<\/h3>\n<p>First we&#8217;ll need to\u00a0edit the pam_duo.conf file and plug in your integration\u00a0key, secret key and api hostname.<br \/>\nNote: there are more options available <a href=\"https:\/\/duo.com\/support\/documentation\/duounix#duo-configuration-options\" target=\"_blank\">here<\/a>\u00a0&#8211; for example defining what you want to happen if the Duo Security servers are unavailable (by default it will bypass 2FA but you can force it to deny log-on).<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/etc\/duo\/pam_duo.conf<\/pre>\n<p>Now we want to edit the PAM common-auth file to\u00a0require 2FA from the pam_duo.so module.<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/etc\/pam.d\/common-auth<\/pre>\n<p>Your config should look like the below &#8211; note that I took out the comments so that it is easier to read.<\/p>\n<pre class=\"lang:default decode:true\">auth requisite pam_unix.so nullok_secure\r\nauth [success=1 default=ignore] \/lib64\/security\/pam_duo.so\r\nauth requisite pam_deny.so\r\nauth required pam_permit.so\r\nauth optional pam_cap.so<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_28_08-mtunc@emtlab-ubuntu01_-.png\" rel=\"attachment wp-att-2049\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2049\" src=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_28_08-mtunc@emtlab-ubuntu01_-.png\" alt=\"2016-01-16 12_28_08-mtunc@emtlab-ubuntu01_ ~\" width=\"629\" height=\"398\" srcset=\"https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_28_08-mtunc@emtlab-ubuntu01_-.png 629w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-12_28_08-mtunc@emtlab-ubuntu01_--300x190.png 300w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/a><\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/etc\/ssh\/sshd_config\r\n\r\n<\/pre>\n<p>Set the following variables:<\/p>\n<pre class=\"lang:default decode:true\">ChallengeResponseAuthentication yes\r\nUsePAM yes\r\nUseDNS no<\/pre>\n<h3>A few more steps for public key authentication<\/h3>\n<p>If you&#8217;re using public key authentication then set the following variables in sshd_config:<\/p>\n<pre class=\"lang:default decode:true\">PubkeyAuthentication yes\r\nPasswordAuthentication no\r\nAuthenticationMethods publickey,keyboard-interactive<\/pre>\n<p>Also you need to make some changes in the pam.d\/sshd config<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/etc\/pam.d\/sshd\r\n<\/pre>\n<p>You need to comment out and add the following lines:<\/p>\n<pre class=\"lang:default decode:true\">#@include common-auth\r\nauth [success=1 default=ignore] \/lib64\/security\/pam_duo.so\r\nauth requisite pam_deny.so\r\nauth required pam_permit.so\r\nauth optional pam_cap.so<\/pre>\n<p>It should look like this:<\/p>\n<p><a href=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-13_34_50-mtunc@emtlab-ubuntu01_-_.ssh_.png\" rel=\"attachment wp-att-2053\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2053\" src=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-13_34_50-mtunc@emtlab-ubuntu01_-_.ssh_.png\" alt=\"2016-01-16 13_34_50-mtunc@emtlab-ubuntu01_ ~_.ssh\" width=\"504\" height=\"168\" srcset=\"https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-13_34_50-mtunc@emtlab-ubuntu01_-_.ssh_.png 504w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-13_34_50-mtunc@emtlab-ubuntu01_-_.ssh_-300x100.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/a><\/p>\n<h3>Final thoughts&#8230;<\/h3>\n<p>By default you will be prompted for 2FA on log-on (obviously). By default you will also be prompted for 2FA when you run sudo &#8211; everytime. If you don&#8217;t want this to happen then have a look at the\u00a0<strong>\/etc\/pam.d\/<\/strong> directory.<\/p>\n<p>Here you will find\u00a0PAM\u00a0<em>authentication tasks<\/em>. You will find one for sudo. If you edit that file to look like the below, you will only be prompted for your password\u00a0and not 2FA.<\/p>\n<p>Again it all depends on your environment and how you want things set-up vs convenience vs security.<\/p>\n<p><a href=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-14_54_39-mtunc@emtlab-ubuntu01_-.png\" rel=\"attachment wp-att-2056\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2056\" src=\"http:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-14_54_39-mtunc@emtlab-ubuntu01_-.png\" alt=\"2016-01-16 14_54_39-mtunc@emtlab-ubuntu01_ ~\" width=\"718\" height=\"272\" srcset=\"https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-14_54_39-mtunc@emtlab-ubuntu01_-.png 718w, https:\/\/emtunc.org\/blog\/wp-content\/uploads\/2016\/01\/2016-01-16-14_54_39-mtunc@emtlab-ubuntu01_--300x114.png 300w\" sizes=\"auto, (max-width: 718px) 100vw, 718px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will go through the steps required to install and configure Duo Security with Ubuntu Server for two factor authentication. This can be adapted to apply to SSH log-ons, sudo access, etc. The Linux PAM (pluggable authentication modules) make this easy to implement and customise. I currently have this implemented on my [&hellip;]<\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[1],"tags":[118,127,214],"class_list":["post-2046","post","type-post","status-publish","format-standard","hentry","category-tech","tag-2fa","tag-duosecurity","tag-ubuntu"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1trTO-x0","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/comments?post=2046"}],"version-history":[{"count":22,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2046\/revisions"}],"predecessor-version":[{"id":2474,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/posts\/2046\/revisions\/2474"}],"wp:attachment":[{"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/media?parent=2046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/categories?post=2046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emtunc.org\/blog\/wp-json\/wp\/v2\/tags?post=2046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}