Configuring ssh traffic

,

I am currently living somewhere without Wi-Fi. When I need to go online, I’ll usually use my phone as a hotspot, or just drive to the local coffee spot and use their public Wi-Fi through a vpn. I’ve also recently gotten back into programming, and have started developing an app that requires a backend hosted on EC2. However, I only want to let traffic in coming from my computer. Is there a way to configure the network settings to do this, given the variable network connections I’ll be making from my computer?

Edit: Optionally, I’d also be fine with some kind of username and password requirement to connect to the backend.

On the security group you can assign to your ec2 there is an option for “my ip” seems like you should still only allow what you need though I.e. ssh etc.

Use SSM Session Manager, this doesn’t require any additional network setup and you don’t even have to allow SSH port on security group. This also uses username and password both on CLI and console, you just need SSM session manager plugin for CLI.

In use a combination of Tailscale and mosh for this personally.

AWS client VPN is another option. Or install a solution like WireGuard on your server.

Fail2ban and only key auth ssh?

Install aws ssm agent.

Do yourself a favour.

Use ZeroTier.

Install ZeroTier on your EC2 instance and configure SSH to listen only on the ZT interface.

Install ZT on your laptop.
Authorise the two devices in ZT admin interface.

It is simple and robust.

You can go one step further and secure your EC2 by making sure SSH only listens in the ZeroTier interface.

Explanation:

ZeroTier is a hosted VPN solution. (Free for 20 devices)

It creates a network for you that is effectively always on and completely private.

As the ZT administrator you authorise what devices can access the network.

Locking down by network restriction sounds like a good idea until something fails. The best way is to use public-private key connection to eliminated password access. I use tinc for that. The method used in this article should work on most Linux.

How to Install Tinc and Set Up a Basic VPN on Ubuntu 18.04

Use Tinc vpn

setup a wireguard tunnel

This is the way

Or TailScale… This works even for RDS, Lambda

That refers to the current IP – in the OP’s case it will be dynamic, so it doesn’t help…:man_shrugging:t2:

Yep my mistake.

Everyone here seems to be saying either

use SSM

or

use $(third party) VPN

That isn’t bad advice but, let’s suppose that you actually want network access back to your box without going through a third party broker. 2 suggestions:

  1. Set up a security group for your EC2 instance. You can manually update the rules to permit traffic from your current location via the AWS API’s - either via the console (web browser) or a script, like this guy or this guy
  2. Use AWS client VPN. The advantage of this is that it’s first party. The downside is that it won’t be the cheapest available option.

Definitely tailscale. Hackers can’t hack ports that aren’t open.

I’m not sure if you’re saying SSM is a third-party service, it isn’t.Or are you saying direct SSH access is better than through SSM? In that case, you can use SSM to SSH directly to the box.

I use these lines in my .ssh/config to access my boxes without allowing any access from the public network:

Host i-*
ProxyCommand sh -c “aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p”

Long before zero tier and wanting to avoid the cost of a vpn, I used something similar to the below.
Squiff mentioned this, and for me it worked a treat.

https://medium.com/@dbclin/a-bash-script-to-update-an-existing-aws-security-group-with-my-new-public-ip-address-d0c965d67f28

SSM is a first party tool as it is made available by AWS. However, it is a third party tool for most software that you would want to interact with your host using. It’s relatively easy to get an EC2 instance with SSM access. Say for instance, you want to do mobile development and you have your back end on EC2. You’re not going to have much luck getting an SSM client going on a mobile phone. Yes, you can tunnel most traffic over SSH and if your SSH is going over SSM then your applications and tooling can be naive for that protocol. I’m aware also of tools like sshuttle. It can still more of a pain to set up depending on your tool set than a VPN or simply public access.