I have successfully set up an sftponly group whose users are put into chroot jail upon sftp connection to an opensuse 13.2 system. The opensuse “cookbook” for doing this can be viewed here: https://en.opensuse.org/SDB:SFTP_server_with_Chroot
These are the modifications to /etc/ssh/sshd_config
# override default of no subsystems
# Original commented out and internal-sftp added
#Subsystem sftp /usr/lib/ssh/sftp-server
Subsystem sftp internal-sftp
Subsystem internal-sftp -l INFO
and then added at bottom of the file:
Match group sftponly
ForceCommand internal-sftp
ChrootDirectory /sftproot/%u
X11Forwarding no
AllowTcpForwarding no
This works really well for a user that is set up when the only group to which the restricted usert is a member only of the sftponly group. The user logs in via their sftp client and cannot go higher than their chroot home. Yay!
Now I have a new requirement that a “typical” user of the system (pre-defined long ago before the sftponly environment for sftp users was added) needs to be able to read some of the files uploaded by the sftp users to a directory beneath their chroot jail home. I think to myself, "No problem. I’ll just add olduserid to the sftponly group, and as long as group-read permission is set for the uploaded file from the sftpuser and group owner is sftoponly, olduserid should be able to read the file. I issue
usermod -a -G sftponly olduserid
so that “olduserid” is now also a member of the sftponly group in addition to its other groups.
I try to ssh login to “olduserid” like I normally do and the login fails because ssh matched the Group sftponly and there has been no chroot home directory set up for olduserid. Syslog shows
Accepted keyboard-interactive/pam for olduserid from ::1 port 35093 ssh2
pam_unix(sshd:session): session opened for user olduserid by (uid=0)
pam_unix(systemd-user:session): session opened for user olduserid by (uid=0)
fatal: chroot into directory without nodev and either noexec or nosuid
pam_unix(sshd:session): session closed for user olduserid
pam_unix(systemd-user:session): session closed for user olduserid
This was interesting as the default group for olduserid was the same as it was before. Nevertheless, some quick googling and I found the suggestion to change the “Match” statement from what I posted above to this:
Match group sftponly, User !olduserid
I make the change and systemctl reload sshd to pick up the change.
This fixes the inability to ssh login olduserid to the expected results and the olduserid can login as before. But the unexpected side effect seems to be that the change breaks the chroot jail for the other sftponly group members who should stay in their chroot jail. WIth an sftp client from a different Linux server, I was able “cd” all the way up into the system root directory. If I remove the “, User !olduserid” from the “Match” line, then the sftp chroot jail for an sftp user whose group is sftponly returns to the desired jail.
Not sure if I have misunderstood or incorrectly implemented the suggested solution. This was the site where I read the suggestion. http://serverfault.com/questions/641470/exclude-a-single-user-from-chroot
Any help is appreciated.