Enable VNC for an Amazon EC2 instance

The default installation of the CentOS variant on an EC2 micro instance is missing some required packages. The packages are available from default CentOS repos which need to be added to the instance yum configuration.

Start vi to edit the repo configuration:

sudo vi /etc/yum.conf

and append the following to the end of the configuration file.

[base]
name=CentOS-5 - Base
mirrorlist=http://mirrorlist.centos.org/?release=5&arch=i386&repo=os
#baseurl=http://mirror.centos.org/centos/5/os/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
[updates]
name=CentOS-5 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=5&arch=i386&repo=updates
#baseurl=http://mirror.centos.org/centos/5/updates/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
[extras]
name=CentOS-5 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=5&arch=i386&repo=extras
#baseurl=http://mirror.centos.org/centos/5/extras/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1

and import the keys for accessing the packages

sudo rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

The yum configuration is all set. Next install the packages using the following commands and enter 'yes' when prompted

sudo yum install vnc-server xterm twm

Once the installation completes successfully, start the VNC server using

 

vncserver :1

 

which configures port 5901 for VNC access. Use the Management Console or the command line commands to create new security rule to allow access to port 5901 for your EC2 instance.

Next, from your client machine used to access the EC2 instance, ensure that you are using the following parameter to your ssh or putty executable

 

-L 5901:localhost:5901

Check that the following processes are running 

 

Xvnc :1 -desktop ip-10-122-177-186:1 (ec2-user) -httpd /usr/share/vnc/classes -auth /home/ec2-user/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 30000 -rfbauth /home/ec2-user/.vnc/passwd -rfbport 5901 -pn
vncconfig -iconic
xterm -geometry 80x24+10+10 -ls -title ip-10-122-177-186:1 (ec2-user) Desktop

 

References

 

https://forums.aws.amazon.com/message.jspa?messageID=196807

https://forums.aws.amazon.com/thread.jspa?threadID=14260