IP アドレスに基づいて特定のユーザーの SSH ログインを制限します。

IP アドレスに基づいて特定のユーザーの SSH ログインを制限します。

ssh特定のユーザーが1つのIPアドレスにのみログインするように制限する方法は?

fooIPアドレス127.0.0.5(最初のサーバー)などのユーザー名がサーバーにあり、公開ssh鍵を介して彼のログイン名だけが残りました。私は特定のIP(私の他のサーバー)でのみこのユーザーにログインアクセスを許可したいと思います。 IP 127.0.0.6

どうやってこれができますか?

答え1

以下でsshd設定を変更できます/etc/ssh/sshd_config

AllowUsers [email protected] [email protected] ....

特定のユーザーが特定の認証方法のみを使用できるようにすることもできます。

Match User my_login
AuthenticationMethods publickey

ただし、次の2つの点に注意してください。設定を変更する前に、物理的な制御や注意を払う必要があります。AllowUsersansオプションのマニュアルページを見て、AuthenticationMethodsそれが意味するものをよりよく理解し、最終的に必要な他のオプションと方法が何であるかを確認することをお勧めします。

答え2

ファイアウォールを設定し、特定のIPのみをポート22に接続することを許可できます。

/etc/nftables.conf

#!/usr/sbin/nft -f

flush ruleset

table inet firewall {

    chain inbound {
        # By default, drop all traffic unless it meets a filter
        # criteria specified by the rules that follow below.
        type filter hook input priority 0; policy drop;

        # Allow traffic from established and related packets.
        ct state established,related accept

        # Drop invalid packets.
        ct state invalid drop

        # Allow loopback traffic.
        iifname lo accept

        # Allow all ICMP and IGMP traffic, but enforce a rate limit
        # to help prevent some types of flood attacks.
        ip protocol icmp limit rate 4/second accept
        ip6 nexthdr ipv6-icmp limit rate 4/second accept
        ip protocol igmp limit rate 4/second accept

        # Allow SSH on port 22 but only from 127.0.0.6
        ip saddr 127.0.0.6 tcp dport 22 accept
    }

    chain forward {
        # Drop everything (assumes this device is not a router)
        type filter hook forward priority 0; policy drop;
    }

    chain outbound {
        # Allow all outbound traffic
        type filter hook output priority 0; policy accept;
    }
}

関連情報