2014-02-09 99 views
2

我有幾臺服務器使用以下sshd配置。AllowGroups和root @ IP

# Authentication: 
PermitRootLogin no 
AllowGroups ssh 
PubkeyAuthentication yes 
PasswordAuthentication no 

這意味着組「ssh」中的每個用戶都可以登錄,但只能使用pubkey。不允許登錄root。

但是必須有一個root的例外:我的備份服務器與$ ip必須以root用戶身份登錄。

我想:

AllowUsers [email protected]$ip 
AllowGroups ssh 

不過的AllowUsers覆蓋AllowGroups聲明。因此,從$ IP只有root可以登錄。

Match User root, Address $ip 
    PermitRootLogin {yes|without-password} 
    AllowUsers root 

Match Address $ip 
    PermitRootLogin {yes|without-password} 
    AllowUsers * 

兩個被完全忽略。組「ssh」中的普通用戶仍然只能登錄。

這是一個簡單的情況,用戶登錄限於pubkey和root登錄限於pubkey和某些IP。怎麼解決?

回答

4

您還沒有發佈整個sshd_config,所以這是一個有點難以重現的情況,但是這似乎工作:

# Main config prohibits all logins 
PermitRootLogin no 
AllowUsers root 

# Permit root logins from a specific address 
Match Address 192.168.1.20 
    PermitRootLogin yes 

# Allow logins to anyone in "ssh" group. 
Match Group ssh 
    AllowUsers * 

另一種解決方案是:

  • 有以下在你的sshd_config

    AllowGroups ssh 
    PermitRootLogin without-password 
    
  • 使root成爲ssh組的成員。

    usermod -a -G ssh root 
    
  • 添加公鑰/root/.ssh/authorized_keys具有受限 源地址,像這樣:

    from=192.168.1.20 ssh-rsa ... 
    

這會得到你想要的東西:

  • 只有會員ssh組可以登錄。
  • root只能從 authorized_keys文件中的特定IP地址登錄。
+0

在authorized_keys中,ip地址必須用引號括起:from =「192.168.1.20」ssh-rsa ... 這兩種解決方案都可以正常工作。我採用授權密鑰的第二種方式 - 也許更「標準的方式」。 非常感謝! – Chickenmarkus

+0

AllowUsers在一場比賽似乎被禁止,並可能在重新啓動時崩潰ssh服務。 (不知道雖然,長篇小說...) – dfherr