<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SFTP | DCMST</title><link>https://portfolio.devcrumbs.com/tag/sftp/</link><atom:link href="https://portfolio.devcrumbs.com/tag/sftp/index.xml" rel="self" type="application/rss+xml"/><description>SFTP</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Tue, 31 Mar 2015 00:00:00 +0000</lastBuildDate><image><url>https://portfolio.devcrumbs.com/media/icon_hu28290437db960aa4e7d19bb9f7230401_6937_512x512_fill_lanczos_center_3.png</url><title>SFTP</title><link>https://portfolio.devcrumbs.com/tag/sftp/</link></image><item><title>SFTP Jailed</title><link>https://portfolio.devcrumbs.com/sftp-jailed/</link><pubDate>Tue, 31 Mar 2015 00:00:00 +0000</pubDate><guid>https://portfolio.devcrumbs.com/sftp-jailed/</guid><description>&lt;p>To configure your server to use a jailed user on SFTP you should do:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Edit the sshd_config file&lt;/p>
&lt;p>We need to comment the following line:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">Subsystem sftp /usr/libexec/openssh/sftp-server
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>And add the uncomment line, your modification will be same as:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Subsystem sftp /usr/libexec/openssh/sftp-server&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Subsystem sftp internal-sftp
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Also, at the end of the file we should to add the next lines:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">Match Group sftponly
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ChrootDirectory %h
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">X11Forwarding no
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">AllowTCPForwarding no
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ForceCommand internal-sftp
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>After save all the changes, we must restart the sshd daemon&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">service sshd restart
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Add &lt;strong>sftponly&lt;/strong> group&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">groupadd sftponly
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Add jailed user and add to &lt;strong>sftponly&lt;/strong> group&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">useradd -m USERNAME
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">passwd USERNAME
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">usermod -aG sftponly,apache USERNAME
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>IMPORTANT&lt;/strong>: Create directory and establish correct permissions&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">chown root:root /home/USERNAME
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">chmod &lt;span class="m">755&lt;/span> /home/USERNAME
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">mkdir /home/USERNAME/TEST.DOMAIN.COM
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">chown apache:apache /home/USERNAME/TEST.DOMAIN.COM
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">chmod &lt;span class="m">775&lt;/span> /home/USERNAME/TEST.DOMAIN.COM
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">mkdir /var/www/vhost/TEST.DOMAIN.COM
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">chown apache:apache /var/www/vhost/TEST.DOMAIN.COM
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">chmod &lt;span class="m">775&lt;/span> /var/www/vhost/TEST.DOMAIN.COM
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Note: &lt;em>If you have any connection problem please double check the permissions on the folders and check the logs on /var/log/secure&lt;/em>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">tail -f /var/log/secure
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Mount DocumentRoot path on jailed user home directory&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">mount -o bind,noatime /var/www/vhost/TEST.DOMAIN.COM/ /home/USERNAME/TEST.DOMAIN.COM
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Make the mount point permanent, editing the fstab file:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">vi /etc/fstab
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Add the mount point at the end of the file:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">/var/www/vhost/TEST.DOMAIN.COM/ /home/USERNAME/TEST.DOMAIN.COM none bind,noatime &lt;span class="m">0&lt;/span> &lt;span class="m">0&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Save and exit&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Test connection:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">sftp SERVERIP
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;/ol></description></item></channel></rss>