IP 주소를 기반으로 특정 사용자에 대한 SSH 로그인 제한
Aug 20 2020
ssh
특정 사용자의 로그인이 하나의 IP 주소에서만 허용되도록 제한하려면 어떻게 해야합니까?
foo
예를 들어 IP 주소 127.0.0.5
(내 첫 번째 서버) 로 서버에 이름이 지정된 사용자가 있으며 ssh
공개 키 를 통해서만 로그인을 남겼습니다 . 특정 IP (내 다른 서버) (예 : IP)에서만이 사용자에게 액세스 로그인을 허용하고 싶습니다 127.0.0.6
.
그게 어떻게 가능해?
답변
2 GiacomoCatenazzi Aug 20 2020 at 20:50
다음에서 sshd의 구성을 변경할 수 있습니다 /etc/ssh/sshd_config
.
AllowUsers [email protected] [email protected] ....
일부 사용자가 일부 인증 방법 만 사용할 수 있도록 선택할 수도 있습니다.
Match User my_login
AuthenticationMethods publickey
그러나 두 가지 사항에주의를 기울여야합니다. 설정을 변경하기 전에 물리적 제어가 있거나 매우 신중해야합니다. 또한 의미를 더 잘 이해하고 궁극적으로 필요한 옵션과 방법을 더 잘 이해하기 위해 매뉴얼 페이지에서 AllowUsers
ans AuthenticationMethods
옵션 을 살펴볼 것을 권장 합니다.
dirdi Aug 20 2020 at 20:27
방화벽을 설정하고 특정 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;
}
}