{"id":539,"date":"2011-01-28T00:30:38","date_gmt":"2011-12-18T13:51:50","guid":{"rendered":"http:\/\/kraftek.com\/blog\/jailing-a-user-in-ssh-without-a-patch-for-openssh\/"},"modified":"2011-01-28T00:30:38","modified_gmt":"2011-12-18T13:51:50","slug":"jailing-a-user-in-ssh-without-a-patch-for-openssh","status":"publish","type":"post","link":"\/blog\/index.php\/jailing-a-user-in-ssh-without-a-patch-for-openssh\/","title":{"rendered":"jailing a user in ssh without a patch for openssh"},"content":{"rendered":"<p>You can use a combination of &#8220;jailkit&#8221; and pam&#8217;s chroot module for this, we&#8217;ll jail user &#8220;rdpm&#8221; in this example.<br \/>\nFirst, get jailkit from http:\/\/olivier.sessink.nl\/jailkit\/ , build it and install it<br \/>\nNow, create a generic jail<br \/>\njk_init -v \/home\/jail sftp scp ssh jk_lsh basicshell<br \/>\nlet&#8217;s now create the user &#8220;rdpm&#8221;<br \/>\nuseradd -m -d \/home\/rdpm -g 10 rdpm<br \/>\npasswd rdpm<br \/>\nWe want this to work only for ssh, so let&#8217;s add a line to \/etc\/pam.d\/sshd to load the chroot module<br \/>\nsession required pam_chroot.so debug<br \/>\nso, now let&#8217;s make rdpm&#8217;s home inside the jail directory<br \/>\nmkdir \/home\/jail\/home\/rdpm<br \/>\nchown rdpm \/home\/jail\/home\/rdpm<br \/>\nYou may, if you want so, mount loopback his real home dir into the jail:<br \/>\nmount &#8211;bind \/home\/rdpm \/home\/jail\/home\/rdpm<br \/>\nAnd you may also make that bind mount permanent:<br \/>\n69\/433<br \/>\necho &#8220;\/home\/rdpm \/home\/jail\/home\/rdpm bind defaults,bind 0 0&#8221; &gt;&gt; \/etc\/fstab<br \/>\nlet&#8217;s copy rdpm&#8217;s auth info into the jail<br \/>\ngrep rdpm \/etc\/passwd &gt;&gt; \/home\/jail\/etc\/passwd<br \/>\ngrep rdpm \/etc\/shadow &gt;&gt; \/home\/jail\/etc\/shadow<br \/>\nLet&#8217;s configure the chroot pam module<br \/>\necho &#8220;rdpm \/home\/jail&#8221; &gt;&gt; \/etc\/security\/chroot.conf<br \/>\nand that&#8217;s all, now &#8220;ssh rdpm@yourserver&#8221; and you&#8217;ll find urself in a jail<br \/>\n70\/433<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use a combination of &#8220;jailkit&#8221; and pam&#8217;s chroot module for this, we&#8217;ll jail user &#8220;rdpm&#8221; in this example. First, get jailkit from http:\/\/olivier.sessink.nl\/jailkit\/ , build it and install it Now, create a generic jail jk_init -v \/home\/jail sftp scp ssh jk_lsh basicshell let&#8217;s now create the user &#8220;rdpm&#8221; useradd -m -d \/home\/rdpm -g [&hellip;]<\/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-539","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=539"}],"version-history":[{"count":0,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}