I was trying to configure SFTP to a list of users, so I thought of creating a few blocks of "Match User" at "/etc/ssh/sshd_config" file.
Something like this:
# User A, B Match User usera,userb ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no ChrootDirectory /mnt/shared/user_a_b # User C Match User userc ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no ChrootDirectory /mnt/shared/user_c
After that, I restarted SSH, logged out of my current user and found a first problem. Since I was using usera I locked myself out of SSH. To solve that, fortunelly, I openned root's shell and removed usera from the first stanza.
Match User userb
Now, when I try to login userb or userc to SFTP I get the error below.
$ sftp userb@localhost userb@localhost's password: packet_write_wait: Connection to ::1 port 22: Broken pipe Connection closed
Basically, the only difference between users is the ChrootDirectory. How could I set up SFTP to multiple users with different folders?
Looking at auth.log, the only messages shown are these:
sshd: Received signal 15; terminating. sshd: Server listening on 0.0.0.0 port 22. sshd: Server listening on :: port 22. sshd: Accepted password for userb from ::1 port 50552 ssh2 sshd: pam_unix(sshd:session): session opened for user userb by (uid=0) sshd: fatal: bad ownership or modes for chroot directory "/mnt/shared/user_a_b" sshd: pam_unix(sshd:session): session closed for user userb
I suppose the issue is with folder permissions, right?
My shared directorys permissions are these:
drwxrwx--T 20 root sambashare 4.0K May 11 16:09 user_a_b drwxrwx--T 2 root sambashare 4.0K May 10 23:23 user_c
What I don't get is that userb is part of shared group:
$ groups userb userb : userb users sambashare