<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://cooker.wbitt.com/skins/common/feed.css?207"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>SFTP chroot - Revision history</title>
		<link>http://cooker.wbitt.com/index.php?title=SFTP_chroot&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.15.1</generator>
		<lastBuildDate>Sat, 20 Jun 2026 09:26:08 GMT</lastBuildDate>
		<item>
			<title>Kamran:&amp;#32;Created page with '&lt;pre&gt; [root@lnxlan215 ~]# tail /etc/ssh/sshd_config  Subsystem	sftp	/usr/libexec/openssh/sftp-server  # Example of overriding settings on a per-user basis #Match User anoncvs #	X…'</title>
			<link>http://cooker.wbitt.com/index.php?title=SFTP_chroot&amp;diff=1509&amp;oldid=prev</link>
			<description>&lt;p&gt;Created page with &amp;#39;&amp;lt;pre&amp;gt; [root@lnxlan215 ~]# tail /etc/ssh/sshd_config  Subsystem	sftp	/usr/libexec/openssh/sftp-server  # Example of overriding settings on a per-user basis #Match User anoncvs #	X…&amp;#39;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
[root@lnxlan215 ~]# tail /etc/ssh/sshd_config &lt;br /&gt;
Subsystem	sftp	/usr/libexec/openssh/sftp-server&lt;br /&gt;
&lt;br /&gt;
# Example of overriding settings on a per-user basis&lt;br /&gt;
#Match User anoncvs&lt;br /&gt;
#	X11Forwarding no&lt;br /&gt;
#	AllowTcpForwarding no&lt;br /&gt;
#	ForceCommand cvs server&lt;br /&gt;
&lt;br /&gt;
Match Group webmasters &lt;br /&gt;
	ChrootDirectory %h&lt;br /&gt;
[root@lnxlan215 ~]# &lt;br /&gt;
&lt;br /&gt;
service sshd restart&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@bilaltest ~]# ssh web1@192.168.122.1&lt;br /&gt;
web1@192.168.122.1's password: &lt;br /&gt;
Read from remote host 192.168.122.1: Connection reset by peer&lt;br /&gt;
Connection to 192.168.122.1 closed.&lt;br /&gt;
[root@bilaltest ~]# &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@lnxlan215 ~]# tail -f /var/log/secure&lt;br /&gt;
May 21 11:20:54 lnxlan215 sshd[23458]: pam_unix(sshd:session): session opened for user kamran by (uid=0)&lt;br /&gt;
May 21 11:20:58 lnxlan215 sshd[23458]: pam_unix(sshd:session): session closed for user kamran&lt;br /&gt;
May 21 11:21:09 lnxlan215 sshd[23502]: Accepted password for web1 from 192.168.122.119 port 40135 ssh2&lt;br /&gt;
May 21 11:21:09 lnxlan215 sshd[23502]: pam_unix(sshd:session): session opened for user web1 by (uid=0)&lt;br /&gt;
May 21 11:21:09 lnxlan215 sshd[23511]: fatal: bad ownership or modes for chroot directory &amp;quot;/home/web1&amp;quot;&lt;br /&gt;
May 21 11:21:09 lnxlan215 sshd[23502]: pam_unix(sshd:session): session closed for user web1&lt;br /&gt;
May 21 11:21:39 lnxlan215 sshd[23554]: Accepted password for web1 from 192.168.122.119 port 40136 ssh2&lt;br /&gt;
May 21 11:21:39 lnxlan215 sshd[23554]: pam_unix(sshd:session): session opened for user web1 by (uid=0)&lt;br /&gt;
May 21 11:21:39 lnxlan215 sshd[23562]: fatal: bad ownership or modes for chroot directory &amp;quot;/home/web1&amp;quot;&lt;br /&gt;
May 21 11:21:39 lnxlan215 sshd[23554]: pam_unix(sshd:session): session closed for user web1&lt;br /&gt;
^C&lt;br /&gt;
[root@lnxlan215 ~]# &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Right, this is on purpose. We ban this because allowing a user write&lt;br /&gt;
access to a chroot target is dangerously similar to equivalence with&lt;br /&gt;
allowing write access to the root of a filesystem.&lt;br /&gt;
&lt;br /&gt;
If you want the default directory that users start in to be writable&lt;br /&gt;
then you must create their home directory under the chroot. After&lt;br /&gt;
sshd(8) has chrooted to the ChrootDirectory, it will chdir to the&lt;br /&gt;
home directory as normal. So, for a passwd line like:&lt;br /&gt;
&lt;br /&gt;
djm:*:1000:1000:Damien Miller:/home/djm:/bin/ksh&lt;br /&gt;
&lt;br /&gt;
Create a home directory &amp;quot;/chroot/djm/home/djm&amp;quot;. Make the terminal &amp;quot;djm&amp;quot;&lt;br /&gt;
directory user-owned and writable (everything else must be root-owned).&lt;br /&gt;
Set &amp;quot;ChrootDirectory /chroot&amp;quot; in /etc/config.&lt;br /&gt;
&lt;br /&gt;
The directory specified for “ChrootDirectory” and all its parents up to / should be :&lt;br /&gt;
# owned by root&lt;br /&gt;
# not group or other writable&lt;br /&gt;
&lt;br /&gt;
A variant of this that yields less deep directory trees would be to set&lt;br /&gt;
the passwd file up as:&lt;br /&gt;
&lt;br /&gt;
djm:*:1000:1000:Damien Miller:/upload:/bin/ksh&lt;br /&gt;
&lt;br /&gt;
Create &amp;quot;/chroot/djm/upload&amp;quot;, with &amp;quot;upload&amp;quot; the only user-owned and writable&lt;br /&gt;
component. &lt;br /&gt;
&lt;br /&gt;
------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@lnxlan215 ~]# mkdir /ssh-chroot/home/web1 -p&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
man 5 sshd_config&lt;br /&gt;
&lt;br /&gt;
     ChrootDirectory&lt;br /&gt;
             Specifies the pathname of a directory to chroot(2) to after authentication.  All components of the pathname must be root-owned directories&lt;br /&gt;
             that are not writable by any other user or group.  After the chroot, sshd(8) changes the working directory to the user's home directory.&lt;br /&gt;
&lt;br /&gt;
             The pathname may contain the following tokens that are expanded at runtime once the connecting user has been authenticated: %% is replaced&lt;br /&gt;
             by a literal '%', %h is replaced by the home directory of the user being authenticated, and %u is replaced by the username of that user.&lt;br /&gt;
&lt;br /&gt;
             The ChrootDirectory must contain the necessary files and directories to support the user's session.  For an interactive session this&lt;br /&gt;
             requires at least a shell, typically sh(1), and basic /dev nodes such as null(4), zero(4), stdin(4), stdout(4), stderr(4), arandom(4) and&lt;br /&gt;
             tty(4) devices.  For file transfer sessions using “sftp”, no additional configuration of the environment is necessary if the in-process sftp&lt;br /&gt;
             server is used, though sessions which use logging do require /dev/log inside the chroot directory (see sftp-server(8) for details).&lt;br /&gt;
&lt;br /&gt;
             The default is not to chroot(2).&lt;br /&gt;
&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
http://www.techrepublic.com/blog/opensource/chroot-users-with-openssh-an-easier-way-to-confine-users-to-their-home-directories/229&lt;br /&gt;
-----------&lt;br /&gt;
&lt;br /&gt;
Notice that if any of the following is missing the users will not be able to logon to the chroot:&lt;br /&gt;
&lt;br /&gt;
    *The /proc filesystem needs to be mounted in the users' chroot.&lt;br /&gt;
&lt;br /&gt;
    *The necessary /dev/pts/ devices need to exist. If the files are generated by your running kernel automatically then you have to manually create them on the chroot's /dev/.&lt;br /&gt;
&lt;br /&gt;
    *The user's home directory has to exist in the chroot, otherwise the ssh daemon will not continue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</description>
			<pubDate>Sat, 21 May 2011 11:29:04 GMT</pubDate>			<dc:creator>Kamran</dc:creator>			<comments>http://cooker.wbitt.com/index.php/Talk:SFTP_chroot</comments>		</item>
	</channel>
</rss>