 |
Lab Handbook |
Remote Desktop using VNC with SSH Tunnel (Windows)
Configure a remote host in PuTTY
If you do not have PuTTY installed on your computer, download and install the free PuTTY SSH client.
When you launch PuTTY, the configuration window opens up. This is where you can set up your remote host connection.
If you have access to a Linux/Unix workstation, use that for the Host Name field. Otherwise, please see your local network administrator for a host that you can use.
Type the full host name into the Host Name field. |
 |
 |
This connection will eventually be used for displaying X windows.
In the left pane, expand the SSH tree by clicking the +.
Select X11.
Check Enable X11 Forwarding. |
 |
 |
In the left pane, select Session.
Enter a name in the Saved Sessions field, and click Save.
Double-click your new saved setting line or select it and click Load to connect to the remote server.
Log in to get a terminal window. |
 |
 |
VNC Server
Use your new PuTTY configuration you set up above to get log into your remote shell account.
Run the following command to start the VNC server:
You may be prompted for a password. This can be anything and is not related to your login password.
The command will display a line similar to the following.
New 'hostname:# (username)' desktop is hostname:# |
Take note of the number (#) following the colon (:). This will be the port number you will need in the SSH tunnel setup, and will be the number you will need to use to eventually terminate the server when you are finished using it.
If you were not prompted for a password and have already configured the VNC server to display a remote desktop, continue with the tunnel setup.
If you were prompted to set a password for the vncserver, it most likely means that this is the first time you have run the command. You will now need to terminate the VNC server and configure the desktop setting so you view a remote desktop environment rather than simple xterm windows. To terminate the server, use the number (#) you were given in the above command. Repace the number (#) in the following command to terminate the program.
Now, edit the xstartup file in your .vnc folder.
Substitute your favorite text editor for vi, if you wish.
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
|
Uncomment the two lines as shown.
Save the file and quit the editor.
Run the vncserver command again.
Configure an SSH tunnel
Be sure you have the number (#) you were given in the above vncserver command.
Assuming you are currently running PuTTY from above, you already have your configuration loaded. If you do not, launch PuTTY and load your previously saved configuration by selecting the session name and clicking Load.
|
 |
 |
Select Tunnels in the left pane.
Enter these values:
Source port: 5900.
To determine the destination port, use the number (#) you were given in the vncserver command above and add it to 5900. For example, if your server is running on :1, use the following.
Destination: hostname:5901
where hostname is the hostname is the same one from above. |
 |
 |
| Click the Add button. Your tunnel will now appear in the list, similar to the figure here. |
 |
 |
Select Session in the left pane.
Click the session name in the Saved Sessions pane.
Click Save. |
 |
 |
At this point, you can click Open to start the SSH terminal. The tunnel will now be active as long as the terminal window stays running.
The next time you run PuTTY, you must open these saved settings by selecting the name in the Saves Sessions pane and clicking Load, then clicking Open, or you can simply double-click the session name to load and run the saved session. |
 |
 |
VNC Viewer
If you don't have it, download VNC Viewer (part of the server package) from www.realvnc.com. When you install it, choose only the VNC Viewer. You do not need to install the server.
You must have an open SSH window with an actively running tunnel for the following to function properly.
When VNC Viewer starts up, enter
VNC server: localhost.
Click OK. |
 |
 |
If you are not prompted for a password, the SSH tunnel is not working. Make sure your tunnel configuration is properly set up and that you are running your SSH session configured with an SSH tunnel to the correct port.
When you quit the VNC Viewer, the remote VNC server stays running. This means that you can reconnect to the same VNC server at a later time, and it will remain in the state that you left it (assuming the remote computer is not shut down).
It is a bad idea to leave VNC servers running indefinitely, as they do take up system resources. Please terminate your VNC servers when you no longer need the remote connection..
Terminate your VNC Server
Recall the number (#) you were given in your vncserver command. Replace # with that number in the following command to teminate the server.
You cannot terminate other users' VNC servers.
In some cases, the system will not let you terminate your own VNC server. If you suspect there is still a VNC server running, use the unix ps command to view the VNC servers running on the system. The first number in each line (although the numbers may wrap as shown) is the processor ID (PID) that you need in order to terminate the server.
$ ps -x | grep Xvnc
1688 pts/0 S 0:00 Xvnc :1 -desktop X -httpd /usr/share/vnc/classes
-auth /home/buff/.Xauthority -geometry 1280x960 -depth 8
-rfbwait 120000 -rfbauth /home/buff/.vnc/passwd -rfbport 5901
-fp unix/:7100
1752 pts/0 S 0:00 Xvnc :2 -desktop X -httpd /usr/share/vnc/classes
-auth /home/buff/.Xauthority -geometry 1280x960 -depth 8
-rfbwait 120000 -rfbauth /home/buff/.vnc/passwd -rfbport 5902
-fp unix/:7100
1842 pts/0 S 0:00 Xvnc :3 -desktop X -httpd /usr/share/vnc/classes
-auth /home/buff/.Xauthority -geometry 1280x960 -depth 8
-rfbwait 120000 -rfbauth /home/buff/.vnc/passwd -rfbport 5903
-fp unix/:7100
$ kill 1842
$ kill 1752 |
In this example, you can see that there are three servers running (perhaps you forgot about some old ones that were running). You can use the unix kill command to terminate them.
As an example, to kill off the servers running on :3 and :2 in this example, use the commands
For more information, please ask your local system administrator. |