{"id":1210,"date":"2009-03-25T09:54:22","date_gmt":"2009-03-25T16:54:22","guid":{"rendered":"http:\/\/softbeam.net\/hobby\/?p=1210"},"modified":"2009-03-25T09:54:22","modified_gmt":"2009-03-25T16:54:22","slug":"not-ftp-any-more","status":"publish","type":"post","link":"https:\/\/softbeam.net\/hobby\/?p=1210","title":{"rendered":"not ftp any more"},"content":{"rendered":"<p>From openssh version 4.9p1 up, chroot jail module has been built in, which makes the chroot jail restriction in sftp as possible as in ftp. Or it means ftp no more!<\/p>\n<p>referring to this link: http:\/\/www.minstrel.org.uk\/papers\/sftp\/builtin\/<\/p>\n<p>after downloading and tar -zxvf the source tar ball:<\/p>\n<blockquote><p>.\/configure &#8211;prefix=\/usr &#8211;sysconfdir=\/etc\/ssh &#8211;with-pam &#8211;with-tcp-wrappers<\/p>\n<p>make; make install<\/p><\/blockquote>\n<p>then vi or nano the \/etc\/ssh\/sshd_config:<\/p>\n<p>replacing the Subsystem line with<\/p>\n<blockquote><p>Subsystem\u00a0\u00a0\u00a0 sftp\u00a0\u00a0\u00a0 internal-sftp<\/p><\/blockquote>\n<p>adding these line at the end of the file:<\/p>\n<blockquote><p>Match group sftponly<\/p>\n<p>ChrootDirectory %h<\/p>\n<p>ForceCommand internal-sftp<\/p>\n<p>AllowTcpForwarding no<\/p><\/blockquote>\n<p>now create the group &#8216;sftponly&#8217;:<\/p>\n<blockquote><p>sudo groupadd sftponly<\/p><\/blockquote>\n<p>now create a user for chroot jailed sftp and this user will also be prevented from ssh-ing:<\/p>\n<blockquote><p>sudo useradd -g sftponly -d \/home\/user1 -s \/bin\/false<\/p><\/blockquote>\n<p>or if you want to assign an already existed user to this purpose:<\/p>\n<blockquote><p>sudo usermod -g sftponly -d \/home\/user1 -s \/bin\/false<\/p><\/blockquote>\n<p>now do something about his directory:<\/p>\n<blockquote><p>sudo chown root:root \/home\/user1; sudo chmod 755 \/home\/user1<\/p><\/blockquote>\n<p>now you can sftp to this chroot jailed directory but you will find you can&#8217;t write into it. Here is the trick:<\/p>\n<blockquote><p>cd \/home\/user1; sudo mkdir home; cd home; sudo mkdir user1; chown user1:sftponly user1<\/p><\/blockquote>\n<p>this solves the problem. This is because in chroot jailed situation, \/home\/user1 actually acts as \/ for sftped user1 and \/home\/user1\/home\/user1 actually acts as \/home\/user1 and since it is owned by user1, it can be written.<\/p>\n<p>Don&#8217;t try to directly chown \/home\/user1 to user1:sftponly or chmod to 777, it&#8217;ll cause sftp login to fail.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From openssh version 4.9p1 up, chroot jail module has been built in, which makes the chroot jail restriction in sftp as possible as in ftp. Or it means ftp no more! referring to this link: http:\/\/www.minstrel.org.uk\/papers\/sftp\/builtin\/ after downloading and tar -zxvf the source tar ball: .\/configure &#8211;prefix=\/usr &#8211;sysconfdir=\/etc\/ssh &#8211;with-pam &#8211;with-tcp-wrappers make; make install then vi &hellip; <a href=\"https:\/\/softbeam.net\/hobby\/?p=1210\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;not ftp any more&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1210","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=\/wp\/v2\/posts\/1210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1210"}],"version-history":[{"count":0,"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=\/wp\/v2\/posts\/1210\/revisions"}],"wp:attachment":[{"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softbeam.net\/hobby\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}