2012-05-31 27 views
1

我有這樣的情況,即sshd應該允許sftp只訪問一組用戶。sshd與多個匹配部分,覆蓋設置

這是很容易通過添加匹配部分像

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

做現在我需要排除一個用戶是這個組的成員。他應該有正常的shell訪問。

Match User username 
    ChrootDirectory ??? 
    ForceCommand ??? 

我在這裏設置了什麼? 是否可以取消設置與其他匹配節前面設置的配置指令?

回答

1

請勿添加Match User部分。相反,通過將他排除在原始匹配之外來排除用戶。

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

Match線的所有條件必須滿足所施加的部分。

我不確定確切的語法。您可能需要報價。

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

首先將設置應用到組,除了用戶名,然後將(其他)設置應用於用戶名。如果您不使用用戶用戶名的「ForceCommand」設置,則不會應用該設置。

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

另一個例子是,你可能需要不同的設置,如果從不同的IP地址

#all users except username1 and username2 default to sftp 
Match User *,!username1,!username2 
    PasswordAuthentication yes 
    AllowTCPForwarding no 
    X11Forwarding no 
    ForceCommand internal-sftp -f LOCAL0 -l INFO 

#normal ssh allowed for users username1 and username2 from the local network 
Match User username1,username2 Address 192.168.0.0/16 
    PasswordAuthentication yes 

#users username1 and username2 not allowed from other networks 
Match User username1,username2 Address *,!192.168.0.0/16 
    PasswordAuthentication yes 
    AllowTCPForwarding no 
    X11Forwarding no 
    ForceCommand /usr/sbin/nologin 
用戶登錄