sshd with multiple match sections, override settings

gurubert picture gurubert · May 31, 2012 · Viewed 19k times · Source

I have the situation where sshd should permit sftp only access to a group of users.

This is easily done by adding a match section like

Match Group groupname
    ChrootDirectory /srv/ftp
    ForceCommand internal-sftp

Now I need to exclude one user that is a member of this group. He should have normal shell access.

Match User username
    ChrootDirectory ???
    ForceCommand ???

What do I set here? Is it possible to unset configuration directives previuosly set with another matching section?

Answer

dave4420 picture dave4420 · May 31, 2012

Don't add a Match User section. Instead, exclude the user by excluding him from the original match.

Match Group groupname User !username
    ChrootDirectory /srv/ftp
    ForceCommand internal-sftp

All criteria on the Match line must be satisfied for the section to be applied.

I am unsure of the exact syntax. You may need quotes.

Match Group groupname User "!username"
    ChrootDirectory /srv/ftp
    ForceCommand internal-sftp