How do you let only your office IP SSH into a server?
BeginnerScenarioSecurity: Firewalls, SGs, NACLs & VPN
Answer
Situation read → Least privilege on port 22.
What I'd do →
- Edit the security group inbound rule:
aws ec2 authorize-security-group-ingress --group-id sg-0abc --protocol tcp --port 22 --cidr 203.0.113.7/32 - Remove any
0.0.0.0/0rule for 22 - Better: use SSM Session Manager and close port 22
- Verify from outside with
nc -vz server 22and from another network, which should time out
Why → A /32 limits access to one address; a timeout from other sources shows the SG is dropping, not rejecting.
Interview tip → Mention that office IPs change, so a VPN with a fixed egress IP is more stable.
More on Security: Firewalls, SGs, NACLs & VPN
Security group versus NACL: explain the differences.BeginnerWhat does it mean that a security group can reference another security group?BeginnerStateful versus stateless firewalls: what is the practical difference?BeginnerWhat is a WAF and where do you place it?BeginnerWhat is the difference between a site-to-site VPN and a client VPN?BeginnerHow does DNAT or port forwarding work on a Linux gateway?Beginner