Enable X on AWS EC2 instance

Spin up an EC2 instance. For this demo, I used an t2.micro instance with the base amazon Linux AMI.

First connect to our machine. You need to find your EC2 instance public dns. It will be something like:
ec2-1-2-3-4-us-west-1.compute.amazonaws.com. The user is always ec2-user.

ssh -i /path/to/pem_file ec2-1-2-3-4-us-west-1.compute.amazonaws.com

Once on the EC2 machine, I needed to install some packages:

sudo yum install xorg-x11-xauth.x86_64 xorg-x11-server-utils.x86_64

Check that X11 forwarding is enabled for ssh. This was a good reference:


Check that the DISPLAY variable is enabled on the EC2 instance

export DISPLAY=:0.0
# or
export DISPLAY=:10.0

Login again using ssh with X11 forwarding

ssh -X -i /path/to/pem_file ec2-1-2-3-4-us-west-1.compute.amazonaws.com

To test:


And you should be good to go. I could use R remotely from my linux desktop with plots showing up.