<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zarathustra Shall Speak &#187; SFTP</title>
	<atom:link href="http://zarathustrashallspeak.com/tag/sftp/feed/" rel="self" type="application/rss+xml" />
	<link>http://zarathustrashallspeak.com</link>
	<description>And you yourself are also this Will to Power.</description>
	<lastBuildDate>Tue, 17 Jan 2012 20:44:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CentOS + chroot’d SFTP With No Patches</title>
		<link>http://zarathustrashallspeak.com/2008/09/19/centos-chrootd-sftp-with-no-patches/</link>
		<comments>http://zarathustrashallspeak.com/2008/09/19/centos-chrootd-sftp-with-no-patches/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 08:07:04 +0000</pubDate>
		<dc:creator>Akairenn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[SFTP]]></category>

		<guid isPermaLink="false">http://zarathustrashallspeak.com/?p=37</guid>
		<description><![CDATA[Note to everyone: STOP USING FTP.  THERE'S NO REASON TO USE FTP!  We got rid of telnet years ago, it's time to ditch conventional FTP, too.]]></description>
			<content:encoded><![CDATA[<p>One of our clients requires an sftp-accessible account on one of their systems, for their own clients to upload files to them.  This is easy enough; the problem is that they&#8217;d really like their clients not to be able to poke around the file system of the box.  This sounds like a job for chroot, no?</p>
<p>The problem with chroot and sftp is that it&#8217;s usually a pain to set up.  Most of the documentation I&#8217;ve read makes references to grabbing the OpenSSH source and patching it.  This is one of the most asinine ideas I&#8217;ve ever come across &#8211; to remove OpenSSH from your distribution&#8217;s package management system is asking to have your system compromised to hell and back.  The good news is, there&#8217;s a way around this.</p>
<p>First, you want to grab an awesome little program called <a href="http://sublimation.org/scponly/wiki/index.php/Main_Page">scponly</a>.</p>
<p>tar -zxf the package somewhere (I suggest /opt or /usr/local/src) and change to the newly-created directory.  Once there, carry out the following:</p>
<pre class="code">
./configure --enable-winscp-compat --enable-scp-compat --enable-chrooted-binary
make
make install
</pre>
<p>Next, edit /etc/shells and add the following line to the bottom of the file:</p>
<pre class="code">
/usr/local/sbin/scponlyc
</pre>
<p>Now change back to the scponly source directory and run:</p>
<pre class="code">
make jail
</pre>
<p>Follow the prompts and it will create a user and home directory that is chrooted.  However, for CentOS/RHEL, there are a few more steps we need to do manually.   Change into the newly created home directory for your chrooted user.   I&#8217;ll denote this in the following instructions by using ~chroot/</p>
<p>Edit ~chroot/etc/ld.so.conf and replace the contents of that file with:</p>
<pre class="code">
/lib
/usr/lib
</pre>
<p>After that, run:</p>
<pre class="code">
ldconfig -r ~chroot/
cp /etc/group ~chroot/etc/
mkdir ~/chroot/dev/
mknod ~chroot/dev/null c 1 3
chmod 666 ~chroot/dev/null
</pre>
<p>&#8230;And Bob&#8217;s your uncle.  Unless you&#8217;re using SELinux, in which case, please view the CentOS section of scponly&#8217;s documentation (where I gathered the above info from) <a href="http://sublimation.org/scponly/wiki/index.php/FAQ#Chroot_and_CentOS_5.x">here</a>.</p>
<p>This is quick, easy and leaves OpenSSH as it is on your system, preventing the impossible choice between having chroot, sftp and a nightmare of package mismanagement, or having sftp without chroot.</p>
<p>One final note: If you follow make jail&#8217;s suggestion, you&#8217;ll have a directory in the chrooted user&#8217;s home directory labelled &#8216;incoming&#8217;.  If you want to have the user automatically taken to that directory upon logging in, modify the user&#8217;s directory in /etc/password along the following lines:</p>
<pre class="code">
/home/directory/example//incoming
</pre>
<p>The // will cause the user to be moved to the following (in this case, incoming/) directory when they log in.</p>
]]></content:encoded>
			<wfw:commentRss>http://zarathustrashallspeak.com/2008/09/19/centos-chrootd-sftp-with-no-patches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

