一部の SFTP ユーザーに SSH アクセスも許可するにはどうすればよいですか?

一部の SFTP ユーザーに SSH アクセスも許可するにはどうすればよいですか?

チーム用に SFTP サーバーを導入していますが、一部のユーザーはサーバーを管理するために SSH アクセスも必要とします。

PAM は AD の sssd です。そのため、SSH に使用する別のローカル ユーザーを作成したり、SSH アクセス専用の別の AD アカウントを作成したりすることはできません。

現在、私はこれを持っています:

Match group server_ftp-only
ChrootDirectory /shared
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

ForceCommand internal-sftp を削除すると、ユーザーは SFTP と SSH の両方を使用できるようになりますが、すべてのユーザーが SFTP を使用できるようにするのではなく、一部のユーザーのみが SFTP を使用できるようにします。

これを追加してみました:

Match group server_admins
AllowUsers *

しかし、それは機能しません。元の Match グループがこの 2 番目の Match グループを上書きしているようです。

考えられる解決策の 1 つは、SSH ユーザーを server_ftp-only セキュリティ グループから server_admins グループに移動して、ForceCommand internal-sftp を使用せずに一致グループ server_admins を作成することですが、server_ftp-only グループにはチーム グループ (Team-A > server_ftp-only) が設定されます。追加のグループを作成して、これらのユーザーをチーム グループから分離することは実際にはできません。

答え1

問題の一部は、私の知る限り、グローバル デフォルトとして設定されているか、別の Match 条件によって設定されている when を条件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
    ...

関連情報