{"id":64,"date":"2012-06-10T12:41:11","date_gmt":"2012-06-10T12:41:11","guid":{"rendered":"http:\/\/rmohan.com\/?p=64"},"modified":"2012-06-18T20:38:45","modified_gmt":"2012-06-18T12:38:45","slug":"centos-6-sftp-chroot-jail","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=64","title":{"rendered":"Centos 6 SFTP chroot Jail"},"content":{"rendered":"<p><strong>Centos 6 SFTP chroot Jail <\/strong><\/p>\n<p>User and Group setup<\/p>\n<p>First you will want to establish the sftponly group<\/p>\n<p>groupadd sftponly<\/p>\n<p>Then create the user with the correct home directories and group<\/p>\n<p>useradd -d \/var\/www\/vhosts\/bob -s \/bin\/false -G sftponly bob<\/p>\n<p>Don\u2019t forget at this point to also add password to these new accounts.<\/p>\n<p>SSHd configuration changes<\/p>\n<p>Now we need to make changes in \/etc\/ssh\/sshd_config to enable SFTP chroot jails in SSH.<\/p>\n<p>Comment out the following line in \/etc\/ssh\/sshd_config:<\/p>\n<p>Subsystem sftp \/usr\/lib\/openssh\/sftp-server<\/p>\n<p>and replace it with this line:<\/p>\n<p>Subsystem sftp internal-sftp<\/p>\n<p>Then add the following set of lines to the very bottom of the file:<\/p>\n<p>Match Group sftponly<\/p>\n<p>ChrootDirectory \/var\/www\/vhosts\/%u<\/p>\n<p>X11Forwarding no<\/p>\n<p>AllowTCPForwarding no<\/p>\n<p>ForceCommand internal-sftp<\/p>\n<p>This creates a special login group that then chroot jailed all users in that group into their own home directory.<\/p>\n<p>Once these file changes are saved you will need to restart SSHd for the changes to take effect, using the following command:<\/p>\n<p>service sshd restart<\/p>\n<p>Permissions cleanup and testing<\/p>\n<p>Last issue to address is the permissions settings, for this example the directories \/var\/www\/vhosts\/bob and \/var\/www\/vhosts\/ted should both be owned by root. The directory \/var\/www\/vhosts\/ted\/site1 should be owned by ted and the directory \/var\/www\/vhosts\/bob\/site1 should be owned by bob.<\/p>\n<p>  chown root \/var\/www\/vhosts\/bob<br \/>\n  ls -la<br \/>\n  chmod go-w \/var\/www\/vhosts\/bob<br \/>\n  chown bob:sftponly \/var\/www\/vhosts\/bob\/fileupload\/<br \/>\n  chown bob:sftponly \/opt\/app\/vhosts\/rbc\/writable\/<br \/>\n  chown bob:sftponly \/opt\/app\/vhosts\/rbc\/codeupload\/<br \/>\n  chmod ug+rwx codeupload fileupload writable<\/p>\n<p>   tail -f \/var\/log\/secure<br \/>\n   tail -f \/var\/log\/audit\/audit.log<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Centos 6 SFTP chroot Jail <\/p>\n<p>User and Group setup<\/p>\n<p>First you will want to establish the sftponly group<\/p>\n<p>groupadd sftponly<\/p>\n<p>Then create the user with the correct home directories and group<\/p>\n<p>useradd -d \/var\/www\/vhosts\/bob -s \/bin\/false -G sftponly bob<\/p>\n<p>Don\u2019t forget at this point to also add password to these new accounts.<\/p>\n<p>SSHd configuration [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/64"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=64"}],"version-history":[{"count":5,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}