{"id":5629,"date":"2014-10-14T18:17:24","date_gmt":"2014-10-15T01:17:24","guid":{"rendered":"http:\/\/blog.networkpresence.co\/?p=5629"},"modified":"2014-10-14T18:17:24","modified_gmt":"2014-10-15T01:17:24","slug":"using-gecos-pam-for-custom-umask-settings-incl-via-chroot-sftp","status":"publish","type":"post","link":"http:\/\/blog.networkpresence.co\/?p=5629","title":{"rendered":"Using GECOS &#038; PAM for custom umask settings, incl via Chroot SFTP"},"content":{"rendered":"<p>The PAM module &#8220;pam_umask&#8221; (installed by default in latest Debian Linux) is very useful for setting user-by-user umask permissions that even work in the constrained\/restrictive (for settings) &#8220;SFTP Chroot&#8221; environment.<\/p>\n<p>The chroot environment of SFTP as provided by SSH is very restrictive in terms of the normal means in Linux for changing the default umask for a user logged in via SFTP and chrooted to a specific directory tree (which can be the common case with SFTP users), so the standard Linux means of setting umask (eg: .bashrc or profile files or other shell-based means of changing umask upon login) don&#8217;t or won&#8217;t work for chrooted SFTP users.<\/p>\n<p>In order to change the default umask (for example: from 0022 to 0002 for default group write umask) for a chrooted SFTP user, the mechanism that still can affect this is the PAM sub-system of Linux, which is specifically enabled in the SSH server configuration by default.<br \/>\n<a href=\"http:\/\/en.wikipedia.org\/wiki\/Pluggable_authentication_module\">PAM <\/a>provides a &#8220;pam_umask&#8221; module (installed in Debian Linux by default) which needs to be enabled for the SSH server&#8217;s login process and this is done in the file: <strong>\/etc\/pam.d\/sshd<\/strong> by adding the following line <em>at the top<\/em> of this file:<\/p>\n<p><code>session optional pam_umask.so<\/code><\/p>\n<p>The above just enables the PAM umask module and doesn&#8217;t change any system behaviour perse, so to set a specific default umask for a user once the PAM umask module is enabled, we use the GECOS field in the passwd file for the user, as mentioned in the &#8216;man page&#8217; for pam_umask. To enact a &#8220;group write&#8221; umask for a user, the following command is run as root:<\/p>\n<p><code>chfn -o \"umask=0002\" username<\/code><\/p>\n<p>Then, if that username has the following chroot-based SFTP settings in the <strong>\/etc\/ssh\/sshd_config<\/strong> SSH server configuration file, when they login to the system via SFTP protocol, they&#8217;ll have a umask that will allow (in this case) group-write permissions by default on any uploaded files and directories:<\/p>\n<p><code>UsePAM yes<\/p>\n<p>Subsystem sftp internal-sftp<\/p>\n<p>Match User username<br \/>\n        ChrootDirectory %h<br \/>\n        ForceCommand internal-sftp<br \/>\n        AllowTcpForwarding no<\/code><\/p>\n<p>FYI,<br \/>\nRichard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The PAM module &#8220;pam_umask&#8221; (installed by default in latest Debian Linux) is very useful for setting user-by-user umask permissions that even work in the constrained\/restrictive (for settings) &#8220;SFTP Chroot&#8221; environment. The chroot environment of SFTP as provided by SSH is &hellip; <a href=\"http:\/\/blog.networkpresence.co\/?p=5629\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,70],"tags":[431,430,427,428,429,78],"class_list":["post-5629","post","type-post","status-publish","format-standard","hentry","category-network-presence","category-sales","tag-chroot","tag-gecos","tag-pam","tag-sftp","tag-ssh","tag-sysadmin"],"_links":{"self":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/5629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5629"}],"version-history":[{"count":4,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/5629\/revisions"}],"predecessor-version":[{"id":5637,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/5629\/revisions\/5637"}],"wp:attachment":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5629"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}