Services >> Cloud >> AWS >> Service >> Compute >> EC2 >> How to connect to your Linux instance using VNC

 

 

EC2 instance configuration


## Connect to your instance as ec2-user using SSH


## install MAT packages

sudo amazon-linux-extras install mate-desktop1.x


## define MAT as your default desktop (for all users)

sudo bash -c 'echo PREFERRED=/usr/bin/mate-session > /etc/sysconfig/desktop'


## Install TigerVNC (server) packages

sudo yum install tigervnc-server


## Configure a VNC password for this user.  When prompted if you want a view-only password, press "n"

vncpasswd


## Create a service for the VNC server

sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service

sudo sed -i 's/<USER>/ec2-user/' /etc/systemd/system/vncserver@.service

sudo systemctl daemon-reload



## enable and start the service

sudo systemctl enable vncserver@:1

sudo systemctl start vncserver@:1



## If you failed to start the service because you started vncserver manually before, you can fix it by



## confirm the instance is running and LISTENING to port :5901rm -f /tmp/.X11-unix/X1
$ sudo netstat -tlnp | grep 5901
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      3644/Xvnc
tcp6       0      0 :::5901                 :::*                    LISTEN      3644/Xvnc



REMOTE Client configuration


## Assuming Windows environment and Putty as the SSH Client


## download TigerVNC viewer 64 bit for windows


## Assuming you already have putty installed, we will use SSH tunnelling to connect to the VNC server over port 22 so that we do not need to open additional firewall for the EC2 instance

putty -ssh -L 5901:localhost:5901 -i path-to-your-private-key ec2-user@EC2-instance-ip


## Keep that SSH session open to use the tunnel

## launch VNCviewer



## When prompted for VNC server, enter localhost:1   (note we are using localhost because we have established an SSH tunnel with the same local default port 5901 mapped to the remote (EC2) VNC server port 5901.  So the viewer connects to localhost at display :1




## When prompted, enter the VNC password for ec2-user that was created earlier.




## You should get the GUI session for user ec2-user