我正在為一個團隊部署 SFTP 伺服器,但其中一些用戶還需要 SSH 存取權來管理伺服器。
PAM 是我們 AD 的 SSD。因此,我無法為他們建立單獨的本機使用者以用於 SSH,或建立單獨的 AD 帳戶僅用於 SSH 存取。
目前,我有這個:
Match group server_ftp-only
ChrootDirectory /shared
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
如果我刪除 ForceCommand 內部 sftp,它將允許使用者同時使用 SFTP 和 SSH,但我不希望所有使用者都使用 SFTP,只希望少數使用者使用。
我嘗試添加這個:
Match group server_admins
AllowUsers *
但這不起作用。看來原始匹配組會覆蓋第二個匹配組。
一個可能的解決方案是將 SSH 使用者從僅 server_ftp 安全性群組中刪除並移入 server_admins 群組,然後建立一個符合群組 server_admins,而不使用 ForceCommand 內部 sftp,但僅 server_ftp 群組由團隊群組填入(Team-A >僅server_ftp)。我確實無法建立其他群組並將這些使用者與其團隊群組分開。
答案1
您的問題部分在於,據我所知,無法使用條件Match
區塊來取消 ForceCommand
設定為全域預設值或由另一個符合條件設定的時間。
那麼你不能做:
# /etc/ssh/sshd_config
# global config ...
# Enable the internal SFTP server and restrict all users to only SFTP
Subsystem sftp internal-sftp
ForceCommand internal-sftp
ChrootDirectory /shared
# ...
# Override and remove the ForceCommand sftp-only restriction
# for users in the server_admins group
Match group server_admins
ChrootDirectory none <=== this does exist
ForceCommand none <=== this does NOT exist
您可以透過實作不同的策略來解決這個問題:不要將其設為ForceCommand
預設值,使預設值保持寬鬆,然後建立一個稍微複雜的Match
塊與否定模式使其適用於每個人(*
),除了的成員server_admins
然後您可以覆蓋預設值並添加限制:
# /etc/ssh/sshd_config
# ...
# your current global config
#
# Enable the internal sftp server but do not set the ForceCommand
Subsystem sftp internal-sftp
# ...
# Everybody except members of the server_admins group are restricted to SFTP
Match group !server_admins,*
ForceCommand internal-sftp
ChrootDirectory /shared
X11Forwarding no
AllowTcpForwarding no
和類似的成員相符server_ftp-only
不也是以下組織的成員server_admins
Match group !server_admins,server_ftp-only
ForceCommand internal-sftp
...