{"id":12,"date":"2006-10-30T21:43:11","date_gmt":"2006-10-30T08:43:11","guid":{"rendered":"http:\/\/www.meta.net.nz\/~daniel\/blog\/?p=12"},"modified":"2006-10-31T10:06:18","modified_gmt":"2006-10-30T21:06:18","slug":"restricting-ssh-password-auth-by-group-or-shell","status":"publish","type":"post","link":"https:\/\/www.meta.net.nz\/~daniel\/blog\/2006\/10\/30\/restricting-ssh-password-auth-by-group-or-shell\/","title":{"rendered":"Restricting ssh password auth by group or shell"},"content":{"rendered":"<p>Matt Brown asked if I could think of any way to allow a certain group of users to scp into a host and use a password, while requiring a valid key pair for most other users. Perry suggested a solution to this a while ago, so I sat down and had a quick look at it, and got it working.<\/p>\n<p>I configured sshd such that:<\/p>\n<p>[code]<\/p>\n<p>PasswordAuthentication no<br \/>\nChallengeResponseAuthentication yes<br \/>\nUsePAM yes<br \/>\n[\/code]<\/p>\n<p>This bypasses direct \/etc\/passwd auth, but allows standard PAM based auth via the ChallengeResponseAuthentication mechanism. This will allow everyone to login with a password if possible, so we need to configure pam. For this, I used the pam_listfile module, checking that the user had a particular shell, \/usr\/bin\/scponly, as their shell:<\/p>\n<p>[code]<\/p>\n<p>cat &#8220;\/usr\/bin\/scponly&#8221; > \/etc\/scpshells<\/p>\n<p>[\/code]<\/p>\n<p>I then edited \/etc\/pam.d\/sshd:<\/p>\n<p>[code]<\/p>\n<p>auth required pam_env.so<br \/>\nauth required pam_listfile.so item=shell sense=allow file=\/etc\/scpshells onerr=fail<br \/>\nauth sufficient pam_unix.so likeauth nullok<br \/>\nauth required pam_deny.so<br \/>\nauth required pam_nologin.so<\/p>\n<p>session required pam_limits.so<br \/>\nsession required pam_unix.so<\/p>\n<p>account required pam_unix.so<\/p>\n<p>password required pam_cracklib.so difok=2 minlen=8 dcredit=2 ocredit=2 retry=3<br \/>\npassword sufficient pam_unix.so nullok md5 shadow use_authtok<br \/>\npassword required pam_deny.so<\/p>\n<p>[\/code]<\/p>\n<p>I probably don&#8217;t need all of that in the sshd pam snippet, but I just dumped the contents of the included files into to to make editing it easier.<\/p>\n<p>To test this I added \/bin\/bash to \/etc\/scpshells, and verified that I could ssh in by using a pasword. I then removed it, and verified that I could no longer ssh in with a password. Combine this with a suitable shell (\/usr\/bin\/scponly), and I can create users that can scp in with a password &#8211; or with a key if they care &#8211; but cannot get a local shell; all other users cannot authenticate via PAM, and so must provide a valid key.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Matt Brown asked if I could think of any way to allow a certain group of users to scp into a host and use a password, while requiring a valid key pair for most other users. Perry suggested a solution to this a while ago, so I sat down and had a quick look at [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,9,4],"tags":[],"_links":{"self":[{"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/posts\/12"}],"collection":[{"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":0,"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.meta.net.nz\/~daniel\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}