1

I've got an Ubuntu Server 20.04 instance running in the cloud. I've configured my accounts to use public key authentication, and will disable password authentication once everything is verified working. I am now trying to configure accounts in the group sftponly are able to connect for SFTP, but not for shell access. I have followed the steps outlined in this post, but it doesn't appear to be working as I expected.

I expect with my configuration that my user, poe, should be able to login and interact with the SFTP subsystem, but they should be CHRoot'd to their home directory, and be unable to access a shell if connected over a terminal like PuTTY. Setting poe's shell to /usr/sbin/nologin prevents them from accessing SSH or SFTP, so their shell is /usr/bin/bash. poe's IDs are:

root@server:/# id poe
uid=1000(poe) gid=1000(poe) groups=1000(poe),1003(sftponly)

My etc/ssh/sshd_config file should be the default for 20.04:

#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes

PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
AuthorizedKeysFile      .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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 "PermitRootLogin without-password".
# 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

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem sftp  internal-sftp

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

My /etc/ssh/sshd_config.d/match-group-sftponly.conf is:

Match Group sftponly
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
AllowAgentForwarding no
PermitTTY no
PermitTunnel no
ForceCommand internal-sftp

When running sshd to test the changes, this is the output it gives me. IPs and key hashes have been redacted, and port 23 is used for testing.

Server logs are on pastebin, because ServerFault thought they were spam :(

At line 150 of the log, it does interestingly say:

debug3: checking match for 'Group sftponly' user poe host <office ip> addr <office ip> laddr <server ip> lport 23
debug1: user poe matched group list sftponly at line 1

but it doesn't seem to matter what my rules are in the match-group-sftponly.conf. I'm sure what I'm missing is something simple, but I can't quite find it.

Zalerinian
  • 121
  • 1
  • 8

1 Answers1

1

I've managed to fix the issue in my case be placing the match command inside the main configuration file, and not an included conf file. It did not matter if the configuration file was included before or after the content of the main file, either.

Having it in a separate file didn't work, but moving the match group to the bottom of the sshd_config file worked, and it now applies the rules in the group.

Zalerinian
  • 121
  • 1
  • 8
  • I suspect the permissions on match-group-sftponly were incorrect and thus discarded by the service. – Jacob Evans May 14 '20 at 20:15
  • @JacobEvans I'm not sure about that, that file's permissions match that of sshd_config (644), and in the log, at line 150, it did state that the user `poe` matched the group, but then it did nothing after that, for some reason. – Zalerinian May 15 '20 at 18:19