![IP 주소를 기반으로 특정 사용자의 SSH 로그인을 제한합니다.](https://linux55.com/image/178919/IP%20%EC%A3%BC%EC%86%8C%EB%A5%BC%20%EA%B8%B0%EB%B0%98%EC%9C%BC%EB%A1%9C%20%ED%8A%B9%EC%A0%95%20%EC%82%AC%EC%9A%A9%EC%9E%90%EC%9D%98%20SSH%20%EB%A1%9C%EA%B7%B8%EC%9D%B8%EC%9D%84%20%EC%A0%9C%ED%95%9C%ED%95%A9%EB%8B%88%EB%8B%A4..png)
ssh
특정 사용자가 하나의 IP 주소에서만 로그인하도록 제한하는 방법은 무엇입니까 ?
foo
IP 주소 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
그러나 다음 두 가지 사항에 주의하십시오. 설정을 변경하기 전에 물리적 제어를 하거나 매우 주의해야 합니다. AllowUsers
ans 옵션 에 대한 매뉴얼 페이지를 살펴보고 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;
}
}