Starting services on port 22 / remote port forwarding through it

0

I have a large machine S that lives behind NAT and can only be accessed via VPN. As a quick access hack, I want to use an EC2 t2.micro instance to serve as a port-forwarding router node so I can use that EC2 instance's public IP and a port that I specify to connect to machine S. This port-forwarding works with high ports. However, I really want to use the default port 22 since the only purpose of this EC2 instance is to forward traffic (so it is a waste to have to specify ports every time). To do this, I changed my /etc/ssh/sshd_config to run normal ssh for the ec2 instance on port 222 instead and I changed some other settings to change the following to yes: AllowTcpForwarding, AllowStreamLocalForwarding, GatewayPorts. This appears insufficient though as I get a binding error when I try to bind to 22. Higher ports (e.g. 2222) work. However, I can't start on 22. I have a TCP rule in my security group for the EC2 instance that allows outbound/inbound traffic for all ip addresses to all ports. Why am I facing this issue? Is there a neat solution. Is there a network-specific instance that better serves this usecase. For weird reasons, I might need to do this more times.

1 Answer
0

Most likely this is an operating system problem: By default (due to historical reasons in the design of Unix (yes, Unix) many years ago): Ports below 1024 can only be used by the root user. Running processes as root isn't always a good idea but you might try that; but I'm sure there are mechanisms in whichever Linux-based operating system you're using that allow you to launch the process as root; bind the port; then change the running user to a "normal" user.

profile pictureAWS
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions