Skip to main content

Ubuntu – Enable remote desktop from the terminal, via ssh

Updated by Tim Rabbetts on
Code

So I had remote desktop working at home and then decided to take my windows machine off line and build a new linux machine.  However, while building the linux machine I messed up the port forwarding for remote desktop on my router.

I am now at work trying to get remote desktop to work on a difference linux ubuntu server which I just use for ssh, and some web stuff.  All I have is an SSH session, can I get remote desktop working?

Installed links2 which is a terminal text based browser with the aim of being able to tweat the port forward settings on my sky router to allow me to remote desktop through to one of my linux boxes which def have rdp setup.

To run links on my routers ip 192.168.0.1 (yours maybe different, google to model)

links2 192.168.0.1 


Nice idea, but I think the add button above uses either some weird form submit or ajax cause it doesn’t work and just gives me a blank page.  Oh well at least I can see my port forwards that are in place.  This got me to thinking, for example say my fakeport80 port forwards 980 port through to my linux box with remote desktop.  If I could only change the remote desktop port to port 980 from 5900 would be sorted.

Install vnc4server instead of using the default remote desktop as part of ubuntu.

sudo apt-get install vnc4server xinetd 

To start server

vnc4server 

Now lets sert what ports are being listened on:

sudo netstat --tcp --udp --listening --program 

Cool, so we have the server installed and running on port 5901, so now we need to change it to 980?

After a bit of looking I find that you can edit this file:

sudo vi /usr/bin/vncserver 


Find the port 5900 line and change so instead of increment 5900 ports it just runs on one port all the time (this should be temporary)

to this

Start a new vnc4server

vnc4server 
PROBLEM: looking in the log file $HOME/.vnc/xxxx.log shows this

By default ports 0 to 1024 are reserved for root.  So found another port 9999 and tried again.

Now start vnc4server and I get better looking results:

The problem now is that I get a grey screen when I login through vnc.  The above errors are saying cant load X11 the windows system correctly.

Change the .vnc/xstartup file and save it.
Uncomment the lines that start with unset and exec.

Comment out the lines that start with xsetroot, vncconfig, xterm and twm.
The final file should look like:

#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm & 


Now start vnc4server and oh my god look at what I get!!

Useful Commands

list processes running with vnc in name

ps -e | grep vnc 
stop process
kill 1234 

show log file contents being updated in realtime (while running vnc4server in different terminal)

tail -f $HOME/.vnc/xxxxxx.log 

Add new comment