IP 주소를 기반으로 특정 사용자의 SSH 로그인을 제한합니다.

IP 주소를 기반으로 특정 사용자의 SSH 로그인을 제한합니다.

ssh특정 사용자가 하나의 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

그러나 다음 두 가지 사항에 주의하십시오. 설정을 변경하기 전에 물리적 제어를 하거나 매우 주의해야 합니다. 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;
    }
}

관련 정보