I am following this tutorial that explains how to use a VNC client to logon to an Amazon EC2 instance. After a few steps, it asks me to login to the instance using port forwarding using this command:

 ssh -L 5902:localhost:5902 -i amazon.pem ubuntu@ec2–52–90–172–228.compute- 

Afterwards I need to use a VNC client to connect to localhost:5902 (I have to use a password that I defined when setting up the VNC server on EC2). Now, I know nothing about security, but how safe is it to use port forwarding like this? What is the possible risk, if any?

  • If you have any reason not to trust the EC2 machine, if you suspect it was compromised, then using VNC is fairly hazardous. X is not a particularly small or security conscious piece of software! Dec 15, 2018 at 9:49

1 Answer 1


The port forwarding is done over the encrypted connection of SSH. So any data that you sent over this connection will be encrypted.

SSH will accept connections on localhost port 5902 and forward those connections to the other host through the SSL tunnel. The security risk of this is particularly that other users or processes on your computer can also connect to localhost port 5902 to make use of this forwarding. If you are on a multi-user system or have a compromised system this can be a problem.

SSH only listens on localhost by default, so other people on the network cannot piggy-back on the port forwarding.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .