<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="https://uname.pingveno.net/blog/index.php/feed/rss2/xslt" ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title># uname -a - Mot-clé - sftp</title>
    <link>https://uname.pingveno.net/blog/index.php/</link>
    <atom:link href="https://uname.pingveno.net/blog/index.php/feed/tag/sftp/rss2" rel="self" type="application/rss+xml" />
    <description>Le blog de uname.pingveno.net</description>
    <language>fr</language>
    <pubDate>Tue, 18 Aug 2026 13:46:21 +0200</pubDate>
    <copyright>Mathieu Pellegrin</copyright>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <generator>Dotclear</generator>
          <item>
        <title>Debian 8 : Limit SSH users to SFTP</title>
        <link>https://uname.pingveno.net/blog/index.php/post/2016/01/07/Limit-SSH-users-to-SFTP-only</link>
        <guid isPermaLink="false">urn:md5:d5a47c46eec6232c19a682eae095d7a1</guid>
        <pubDate>Thu, 18 Feb 2016 10:38:00 +0100</pubDate>
        <dc:creator>Mathieu</dc:creator>
                  <category>Hacks</category>
                          <category>debian</category>
                  <category>jessie</category>
                  <category>server</category>
                  <category>sftp</category>
                  <category>ssh</category>
                <description>&lt;p&gt;Let&amp;#8217;s say you want to configure a secure remote file access for you users, but you can&amp;#8217;t use FTPS for some reasons (problems with passive mode and commercial firewalls&amp;#160;? Yes&amp;#160;!). Your only secure solution is either a VPN, or a SFTP access.&lt;/p&gt;&lt;p&gt;SFTP is great, but it may implies giving full command line access to your end users.&amp;nbsp; In order to prevent that, you could set-up a jailed SSH access with &lt;a href=&quot;http://olivier.sessink.nl/jailkit/&quot;&gt;Jailkit&lt;/a&gt; and some &lt;a href=&quot;http://unix.stackexchange.com/questions/198590/what-is-a-bind-mount&quot;&gt;bind mount&lt;/a&gt;, but it&amp;#8217;s not that trivial to configure and to maintain&amp;#160;; and it may not work with software virtualization (Docker, LXCs&amp;#8230;). There is a simpler solution.&lt;/p&gt;&lt;p&gt;The solution is&amp;#160;: use the native chroot and limitations abilities of OpenSSH. Here is how.&lt;/p&gt;          &lt;h3&gt;Warning!&lt;/h3&gt;&lt;p&gt;You should not configure this on your primary SSH access. By doing so, you will simply lock you out of your server.&lt;/p&gt;&lt;p&gt;In this article, we will set up a completely new instance of OpennSSH server, running next to the original, and handling SFTP only.&lt;/p&gt;&lt;h3&gt;1. Setup the secondary SSH access (SFTP-only)&lt;/h3&gt;&lt;p&gt;Create a new configuration file by copying the primary configuration&amp;#160;:&lt;/p&gt;&lt;pre&gt;cp /etc/ssh/sshd_config /etc/ssh/sftp_config&lt;/pre&gt;&lt;p&gt;Now edit the file &lt;strong&gt;/etc/ssh/sftp_config&lt;/strong&gt; and change the listening port (for instance 10022)&amp;#160;:&lt;/p&gt;&lt;pre&gt;Port 10022&lt;/pre&gt;&lt;p&gt;Change the PID file for this new instance, set something meaningful&amp;#160;:&lt;/p&gt;&lt;pre&gt;PidFile /var/run/sftp.pid&lt;/pre&gt;&lt;p&gt;Then add these lines to&amp;nbsp;&lt;strong&gt;/etc/ssh/sftp_config&lt;/strong&gt;&amp;#160;:&lt;/p&gt;&lt;pre&gt;ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no&lt;/pre&gt;&lt;p&gt;Here is a sample of a full configuration&amp;#160;:&lt;/p&gt;&lt;pre&gt;# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
&lt;strong&gt;Port 10022&lt;/strong&gt;
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

&lt;strong&gt;PidFile /var/run/sftp.pid&lt;/strong&gt;

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile    %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

&lt;strong&gt;X11Forwarding no&lt;/strong&gt;
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

&lt;strong&gt;Subsystem sftp /usr/lib/openssh/sftp-server
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no&lt;/strong&gt;

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of &quot;PermitRootLogin without-password&quot;.
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
&lt;/pre&gt;&lt;p&gt;Now, let&amp;#8217;s configure autostart. Copy &lt;strong&gt;/lib/systemd/system/ssh.service&lt;/strong&gt; to&amp;nbsp;&lt;strong&gt;/lib/systemd/system/sftp.service&lt;/strong&gt; and adjust settings&amp;#160;:&lt;/p&gt;&lt;pre&gt;[Unit]
Description=&lt;strong&gt;OpenBSD Secure Shell server (SFTP only)&lt;/strong&gt;
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS -f &lt;strong&gt;/etc/ssh/sftp.conf&lt;/strong&gt;
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
Alias=&lt;strong&gt;sftp.service&lt;/strong&gt;
&lt;/pre&gt;&lt;p&gt;And enable your service&amp;#160;:&lt;/p&gt;&lt;pre&gt;systemctl enable sftp.service&lt;/pre&gt;&lt;p&gt;Make sure the symlink&amp;nbsp;&lt;strong&gt;/etc/systemd/system/sftp.service&lt;/strong&gt; is created.&lt;/p&gt;&lt;p&gt;And try to start it&amp;#160;:&lt;/p&gt;&lt;pre&gt;service sftp start&lt;/pre&gt;&lt;h3&gt;2. Reconfigure the primary SSH access&lt;/h3&gt;&lt;p&gt;In order to prevent normal users to log into a full shell, we have to change the primary configuration.&lt;/p&gt;&lt;p&gt;The configuration file should be located in &lt;strong&gt;/etc/ssh/sshd_config&lt;/strong&gt; . Add an AllowUsers or AllowGroups directive to this file&amp;#160;:&lt;/p&gt;&lt;pre&gt;# One or the other but not both!
AllowUsers root admin
#AllowGroups sudo
&lt;/pre&gt;&lt;p&gt;Here is a sample of a full configuration&amp;#160;:&lt;/p&gt;&lt;pre&gt;# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
&lt;strong&gt;Port 22&lt;/strong&gt;
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
&lt;strong&gt;AllowUsers root admin&lt;/strong&gt;

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile    %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding no
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

UsePAM yes&lt;/pre&gt;&lt;p&gt;Restart your primary SSH access, but &lt;strong&gt;don&amp;#8217;t close your terminal afterwards&lt;/strong&gt;&amp;#160;:&lt;/p&gt;&lt;pre&gt;service ssh restart&lt;/pre&gt;&lt;p&gt;Now open a new terminal and check that your primary SSH is still working. If not, rollback your configuration.&lt;/p&gt;&lt;h3&gt;3. Conclusion&lt;/h3&gt;&lt;p&gt;Now you should have two SSH sockets listening&amp;#160;: one for everyone using exclusively SFTP, and the other with full SSH access for authorized accounts.&lt;/p&gt;&lt;p&gt;Don&amp;#8217;t hesitate to reply in comments if you encounter problems. &lt;img src=&quot;/blog/themes/mathedit_material3/smilies/smile.png&quot; alt=&quot;:)&quot; class=&quot;smiley&quot;&gt;&lt;/p&gt;&lt;h3&gt;Sources&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://wiki.archlinux.org/index.php/SFTP_chroot&quot;&gt;https://wiki.archlinux.org/index.php/SFTP_chroot&lt;/a&gt;&lt;/p&gt;</description>
        
              </item>
      </channel>
</rss>
