<?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é - ssh</title>
    <link>https://uname.pingveno.net/blog/index.php/</link>
    <atom:link href="https://uname.pingveno.net/blog/index.php/feed/tag/ssh/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>
          <item>
        <title>Configure 2-factor Yubikey authentication for Debian : the easiest way</title>
        <link>https://uname.pingveno.net/blog/index.php/post/2013/08/06/Configure-2-factor-Yubikey-authentication-for-Debian-%3A-the-easiest-way</link>
        <guid isPermaLink="false">urn:md5:db871557ab4246d3da107e8cd37a6384</guid>
        <pubDate>Tue, 06 Aug 2013 00:20:00 +0200</pubDate>
        <dc:creator>Mathieu</dc:creator>
                  <category>Hacks</category>
                          <category>2-factor authentication</category>
                  <category>debian</category>
                  <category>PAM</category>
                  <category>server</category>
                  <category>ssh</category>
                  <category>token</category>
                  <category>yubico</category>
                  <category>yubikey</category>
                <description>          &lt;p&gt;One of last five years trending topics is the rise of Token authentication, to provide a safer way to authenticate than the classic login/password couple.&lt;/p&gt;
&lt;p&gt;Today I will show you how to configure a 2-factor authentication (login/password + yubikey), in order to use it with your local Unix users as well as with SSH login (PAM powered).&lt;/p&gt;
&lt;p&gt;In this tutorial, I will use the Yubico API, because it&amp;#8217;s simpler. When using the API, the validity check will be computed by Yubico servers. By the way, you can set up your own authentication server if you don&amp;#8217;t want to depend on Yubico servers.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;p&gt;First things first, you have to afford a Yubikey at &lt;a hreflang=&quot;en&quot; href=&quot;http://www.yubico.com/&quot;&gt;http://www.yubico.com/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get your &lt;strong&gt;Yubikey ID.&lt;/strong&gt; You can use the 12 first digit of every Yubikey generated password, but you can also generate it from &lt;a hreflang=&quot;en&quot; href=&quot;http://demo.yubico.com/php-yubico/Modhex_Calculator.php&quot;&gt;http://demo.yubico.com/php-yubico/Modhex_Calculator.php&lt;/a&gt;&lt;br /&gt;For lazy people, type this in a shell and activate your Yubikey&amp;#160;: &lt;code&gt;read -p &quot;Enter a YubiKey OTP: &quot; s &amp;amp;&amp;amp; echo 'The key id is' ${s:0:12}&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a &lt;code&gt;.yubico&lt;/code&gt; directory in your home, and create a file named &lt;code&gt;authorized_yubikeys&lt;/code&gt; inside it. Fill this file with your &lt;strong&gt;unix username&lt;/strong&gt; and &lt;strong&gt;Yubikey ID&lt;/strong&gt; like that&amp;#160;: &lt;code&gt;username:yubikeyid&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, create a id/secret couple for each server ou service you want to authenticate&amp;#160;: &lt;a hreflang=&quot;en&quot; href=&quot;https://upgrade.yubico.com/getapikey/&quot;&gt;https://upgrade.yubico.com/getapikey/&lt;/a&gt;&lt;br /&gt;The ID returned after submitting the URL is the &lt;strong&gt;service ID&lt;/strong&gt;, and the &lt;strong&gt;secret&lt;/strong&gt; is the associated secret. Every pair ID/secret is unique.&lt;br /&gt;You could use the same id/secret for every server you configure, but it is not intended for&amp;#160;: you should use a different id/secret couple for every different server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Log in to your server &lt;strong&gt;as root&lt;/strong&gt;, and install &lt;code&gt;libpam-yubico&lt;/code&gt; (from apt&amp;#160;: &lt;code&gt;apt-get install libpam-yubico&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And configure it&amp;#160;: &lt;code&gt;sudo dpkg-reconfigure libpam-yubico&lt;/code&gt;. When prompted, set the &lt;strong&gt;service ID&lt;/strong&gt; in place of the N in &lt;em&gt;id=N&lt;/em&gt; and the &lt;strong&gt;secret&lt;/strong&gt; in place of the K in &lt;em&gt;key=K&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then apply the configuration with the command &lt;code&gt;pam-auth-update&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;#8217;s all&amp;#160;! Every PAM-compliant authentication will now ask for the Yubikey code to authenticate (as well as login and password). When login from SSH, juste activate your Yubikey after typing your password, before typing &amp;#8220;enter&amp;#8221;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Warning&amp;#160;: if you messed up the Yubikey configuration and are using &amp;#8220;sudo&amp;#8221; before every command, you will be locked outside your server&amp;#160;! After dpkg-reconfigure, if you checked &amp;#8220;Yubico authentication&amp;#8221;,&amp;nbsp;it will ask for a Yubikey code every time a &amp;#8220;sudo&amp;#8221; authentication is required, so keep a root terminal opened to revert your changes.&lt;/strong&gt;&lt;/p&gt;</description>
        
              </item>
      </channel>
</rss>
