<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help with sftp-only chroot configuration. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-sftp-only-chroot-configuration/m-p/6272515#M529464</link>
    <description>&lt;P&gt;I did something similar on RHEL 6 recently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem might be two-fold:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;modern sshd has a hard requirement that the ChrootDirectory is owned by root and not writeable by anyone else.&lt;/LI&gt;&lt;LI&gt;sshd reads the home directory pathname from the real /etc/passwd, then performs the chroot, and then tries to apply the real home directory pathname within the chroot (if your sshd is newer than RHEL 6's, there might have been a patch to improve this behavior). If a directory matching the home directory pathname does not exist within the chroot, it falls back to / within the chroot.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You might be able to work around the ChrootDirectory ownership requirement by using ACLs, since sshd might not be able to check that. But I've understood there is a security-related reason why the check is implemented, and this workaround might become useless if/when sshd is updated to check for ACLs too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Relying on the "fallback to /" behavior might also cause the user to see scary "home directory not found" error messages, or pollute the logs with them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I considered patching sshd to try removing the pathname elements matching the ChrootDirectory setting from the beginning of the home directory path, but in my case, using a non-default sshd was not an option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I did it like this:&lt;/P&gt;&lt;P&gt;I specified the home directory path for chrooted users as /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt;, then set the ChrootDirectory parameter to "/sftp/%u_chroot".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I made a couple of symbolic links, exactly like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cd /sftp/&amp;lt;username&amp;gt;_chroot&lt;/P&gt;&lt;P&gt;ln -s . /sftp/&amp;lt;username&amp;gt;_chroot/sftp&lt;/P&gt;&lt;P&gt;ln -s . /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt;_chroot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a result, when the home directory pathname is read from /etc/passwd, the result is /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt; and all is well. When a SFTP session logs in and gets chrooted to /sftp/&amp;lt;username&amp;gt;_chroot,&lt;/P&gt;&lt;P&gt;the same pathname will match the symbolic links:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;/sftp will match the symlink at /sftp/&amp;lt;username&amp;gt;_chroot/sftp, which points to .&lt;/LI&gt;&lt;LI&gt;then, &amp;lt;username&amp;gt;_chroot will match the symlink at &amp;lt;/sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt;_chroot, which points to . again.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So, within the chrooted environment, the pathname /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt; maps to /././&amp;lt;username&amp;gt;, which is obviously the same as /&amp;lt;username&amp;gt;. Now, that can be a valid user home directory within the chroot, and can be owned by the user. Obviously, if you want to use SSH keys for authentication, the standard rules apply: the home directory and the .ssh sub-directory must not be group or world writeable. Sub-directories of the home directory can be set however you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this set-up, you can also easily set up /sftp/&amp;lt;username&amp;gt;_chroot/etc with a minimal /etc/passwd and /etc/group, to allow the chrooted SFTP client to see human-readable user/group names instead of UID/GID numbers. (Those user/group names don't even have to match the true user/group names.)&lt;/P&gt;&lt;P&gt;If you need copies of any other system files, these can be neatly placed to other corresponding sub-directories ofthe /sftp/&amp;lt;username&amp;gt;_chroot level and made read-only, so the chrooted user won't be able to screw up his environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if your users care about file timestamps in the chrooted environment and your timezone uses DST, you might need to provide a copy of /usr/lib/tztab as /sftp/&amp;lt;username&amp;gt;_chroot/usr/lib/tztab, and make sure that the SFTP session gets a valid TZ environment variable.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Nov 2013 09:48:30 GMT</pubDate>
    <dc:creator>Matti_Kurkela</dc:creator>
    <dc:date>2013-11-18T09:48:30Z</dc:date>
    <item>
      <title>Help with sftp-only chroot configuration.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-sftp-only-chroot-configuration/m-p/6272455#M529463</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to create a new chrooted sftp-only environment to replace and old plain jailed &amp;nbsp;FTP structure.&lt;/P&gt;
&lt;P&gt;The idea is to put together a set of chrooted sftp-only users which should in the home directories under /sftp, each one of them chrooted in its home directory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the sftp users to be logged directly into their homes under /sftp/home, so I've put the following directive in the sshd_config file: &amp;nbsp;ChrootDirectory %h.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I chown the home user directories (for instance, /sftp/home/user) to the respective user, I get an error like this when try ing to log in with a SFTP client:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;fatal: bad ownership or modes for chroot directory "/sftp/home/user"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've reading up on this issue and it seems I /sftp/home/user must be owned by root... but that doesn't work for me since I want the users to be able to write in their home directory (wihout having to chmod the home dirs to 777....).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way of solving this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. This thread has been moved&amp;nbsp;from HP-UX &amp;gt; General to HP-UX &amp;gt; networking. - Hp Forum moderator&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2013 02:40:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-sftp-only-chroot-configuration/m-p/6272455#M529463</guid>
      <dc:creator>mpua</dc:creator>
      <dc:date>2013-11-19T02:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help with sftp-only chroot configuration.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-sftp-only-chroot-configuration/m-p/6272515#M529464</link>
      <description>&lt;P&gt;I did something similar on RHEL 6 recently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem might be two-fold:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;modern sshd has a hard requirement that the ChrootDirectory is owned by root and not writeable by anyone else.&lt;/LI&gt;&lt;LI&gt;sshd reads the home directory pathname from the real /etc/passwd, then performs the chroot, and then tries to apply the real home directory pathname within the chroot (if your sshd is newer than RHEL 6's, there might have been a patch to improve this behavior). If a directory matching the home directory pathname does not exist within the chroot, it falls back to / within the chroot.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You might be able to work around the ChrootDirectory ownership requirement by using ACLs, since sshd might not be able to check that. But I've understood there is a security-related reason why the check is implemented, and this workaround might become useless if/when sshd is updated to check for ACLs too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Relying on the "fallback to /" behavior might also cause the user to see scary "home directory not found" error messages, or pollute the logs with them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I considered patching sshd to try removing the pathname elements matching the ChrootDirectory setting from the beginning of the home directory path, but in my case, using a non-default sshd was not an option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I did it like this:&lt;/P&gt;&lt;P&gt;I specified the home directory path for chrooted users as /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt;, then set the ChrootDirectory parameter to "/sftp/%u_chroot".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I made a couple of symbolic links, exactly like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cd /sftp/&amp;lt;username&amp;gt;_chroot&lt;/P&gt;&lt;P&gt;ln -s . /sftp/&amp;lt;username&amp;gt;_chroot/sftp&lt;/P&gt;&lt;P&gt;ln -s . /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt;_chroot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a result, when the home directory pathname is read from /etc/passwd, the result is /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt; and all is well. When a SFTP session logs in and gets chrooted to /sftp/&amp;lt;username&amp;gt;_chroot,&lt;/P&gt;&lt;P&gt;the same pathname will match the symbolic links:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;/sftp will match the symlink at /sftp/&amp;lt;username&amp;gt;_chroot/sftp, which points to .&lt;/LI&gt;&lt;LI&gt;then, &amp;lt;username&amp;gt;_chroot will match the symlink at &amp;lt;/sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt;_chroot, which points to . again.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So, within the chrooted environment, the pathname /sftp/&amp;lt;username&amp;gt;_chroot/&amp;lt;username&amp;gt; maps to /././&amp;lt;username&amp;gt;, which is obviously the same as /&amp;lt;username&amp;gt;. Now, that can be a valid user home directory within the chroot, and can be owned by the user. Obviously, if you want to use SSH keys for authentication, the standard rules apply: the home directory and the .ssh sub-directory must not be group or world writeable. Sub-directories of the home directory can be set however you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this set-up, you can also easily set up /sftp/&amp;lt;username&amp;gt;_chroot/etc with a minimal /etc/passwd and /etc/group, to allow the chrooted SFTP client to see human-readable user/group names instead of UID/GID numbers. (Those user/group names don't even have to match the true user/group names.)&lt;/P&gt;&lt;P&gt;If you need copies of any other system files, these can be neatly placed to other corresponding sub-directories ofthe /sftp/&amp;lt;username&amp;gt;_chroot level and made read-only, so the chrooted user won't be able to screw up his environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if your users care about file timestamps in the chrooted environment and your timezone uses DST, you might need to provide a copy of /usr/lib/tztab as /sftp/&amp;lt;username&amp;gt;_chroot/usr/lib/tztab, and make sure that the SFTP session gets a valid TZ environment variable.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2013 09:48:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-sftp-only-chroot-configuration/m-p/6272515#M529464</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2013-11-18T09:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help with sftp-only chroot configuration.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-sftp-only-chroot-configuration/m-p/6277491#M529465</link>
      <description>&lt;P&gt;Many thanks Matti, sorry I couldnt answer before. I'll try to setup this configuration you're suggesting. Let's see how it goes!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2013 15:26:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-sftp-only-chroot-configuration/m-p/6277491#M529465</guid>
      <dc:creator>mpua</dc:creator>
      <dc:date>2013-11-21T15:26:47Z</dc:date>
    </item>
  </channel>
</rss>

