Ubuntu Remote Desktop – multiple users

When I got my new dedicated server setup with Ubuntu server 12.04 LTS, I wanted to use it both for website hosting and multiple users remote desktop work.
It took me some time to arrange all the steps to have the above completed, and as far as the hosting part was pretty easy, the multiple Ubuntu users desktop setup needed some jugs of coffee before start working as I wanted it.

So, I presume you have logged in to your server with some user already, so we will stat with updating the system:

  1. sudo apt-get update

Next, as I want all Gnome desktop features, will install it completely with:

  1. sudo apt-get install ubuntu-desktop

Unity looks fancy, but I want the old Gnome panel, and I do not need “compiz”, so:

  1. sudo apt-get remove compix unity
  2.  
  3. sudo apt-get install gnome-panel

Next what we need is a VNC server.

  1. sudo apt-get install vnc4server

The tricky part here is that you have to create several configuration files for the Ubuntu Remote Desktop user. This is really time consuming if you have to read all the settings and creating the files by yourself.

It is more easy to start the VNC server which will create the files automatically:

  1. vnc4server :2

You will be asked for a password so enter it, and then kill the server as we have to make some configuration changes:

  1. vnc4server -kill :2

Edit the xstartup configuration file:

  1. vi .vnc/xstartup

And make it looks like this:

  1. #!/bin/sh
  2.  
  3. [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
  4. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
  5. xsetroot -solid grey
  6. vncconfig -iconic &
  7. x-window-manager &
  8. gnome-panel &
  9. gnome-session &

Now you can start the vnc server with this:

  1. vnc4server :2 -geometry 1024×768 -depth 24

Certainly you can change the settings if you want different Remote Desktop geometry.

Now use your preferred VNC client – http://remmina.sourceforge.net/ (Linux) and http://www.tightvnc.com/download.php (Windows) are my suggestions – and connect to the Ubuntu Remote Desktop server using x.x.x.x:2 as (:2) is the number of display used to run for the client. If you have more than one running you should use different number at the end.

As I saying different desktops, I am going to add another user to my Ubuntu Remote Desktop server.
For this I will need to repeat the above steps for creating (and starting) the VNC profile for each user. This one is not yet automatically implemented, but it is not a big deal.
First I will add another user:

  1. sudo adduser newuser

Complete the several steps for creating the user which is including creating the password and user personal information.
(A little trick when you want to add user with administrative privileges is to type the command as : adduser admin
)
Then start the VNC server once to create the VNC password:

  1. sudo su newuser vnc4server :3
  2. sudo su newuser vnc4server -kill :3

Open VNC startup file for the ‘newuser’

  1. sudo vi /home/newuser/.vnc/xstartup

And paste the same configuration as for the first user:

  1. #!/bin/sh
  2.  
  3. [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
  4. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
  5. xsetroot -solid grey
  6. vncconfig -iconic &
  7. x-window-manager &
  8. gnome-panel &
  9. gnome-session &

Save the file and start the service

  1. sudo su newuser vnc4server :3 -geometry 1024×768 -depth 24

Now using VNC client you can connect to the new user Desktop as going to x.x.x.x:3 address.

The next step is to automate a little bit the start-up precess for these Ubuntu Remote Desktop users. Otherwise you have to start vnc4server for each user when the server is rebooted.

So, switch to root (it is just more easier) and then create vncserver folder and create file as vncservers.conf:

  1. sudo su -
  2. mkdir -p /etc/vncserver
  3. vi /etc/vncserver/vncservers.conf

Inside put the following massive:

  1. VNCSERVERS="2:user 3:newuser"
  2. VNCSERVERARGS[2]="-geometry 1024×768 -depth 24"
  3. VNCSERVERARGS[3]="-geometry 1024×768 -depth 24"

Where ‘user’ is the main user you are dealing with (the one we configured VNC for initially) and ‘newuser’ which is the second user are we have created. If you have more users created and the above steps for settings passwords and vnc4srver start-up completed, add more lines accordingly wit (:4),(:5) etc. screens.

Then create startup script for VNC server as:

  1. vi /etc/init.d/vncserver

And put the following lines inside:

  1. #!/bin/bash
  2.  
  3. unset VNCSERVERARGS
  4. VNCSERVERS=""
  5. [ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
  6. prog=$"VNC server"
  7.  
  8. start() {
  9.         . /lib/lsb/init-functions
  10.         REQ_USER=$2
  11.         echo -n $"Starting $prog: "
  12.         ulimit -S -c 0 >/dev/null 2>&1
  13.         RETVAL=0
  14.         for display in ${VNCSERVERS}|>
  15.         do
  16.                 export USER="${display##*:}"
  17.                 if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER}|> ; then
  18.                         echo -n "${display} "
  19.                         unset BASH_ENV ENV
  20.                         DISP="${display%%:*}"
  21.                         export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
  22.                         su ${USER}|> -c "cd ~${USER} && [ -f .vnc/passwd ] && vnc4server :${DISP} ${VNCUSERARGS}"
  23.                 fi
  24.         done
  25. }
  26.  
  27. stop() {
  28.         . /lib/lsb/init-functions
  29.         REQ_USER=$2
  30.         echo -n $"Shutting down VNCServer: "
  31.         for display in ${VNCSERVERS}|>
  32.         do
  33.                 export USER="${display##*:}"
  34.                 if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER}|> ; then
  35.                         echo -n "${display} "
  36.                         unset BASH_ENV ENV
  37.                         export USER="${display##*:}"
  38.                         su ${USER}|> -c "vnc4server -kill :${display%%:*}" >/dev/null 2>&1
  39.                 fi
  40.         done
  41.         echo -e "\n"
  42.         echo "VNCServer Stopped"
  43. }
  44.  
  45. case "$1" in
  46. start)
  47. start $@
  48. ;;
  49. stop)
  50. stop $@
  51. ;;
  52. restart|reload)
  53. stop $@
  54. sleep 3
  55. start $@
  56. ;;
  57. condrestart)
  58. if [ -f /var/lock/subsys/vncserver ]; then
  59. stop $@
  60. sleep 3
  61. start $@
  62. fi
  63. ;;
  64. status)
  65. status Xvnc
  66. ;;
  67. *)
  68. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  69. exit 1
  70. esac

Make the script executable, and add it to the startup scripts:

  1. chmod +x /etc/init.d/vncserver
  2.  
  3. update-rc.d vncserver defaults 99

Now:

  1. service vncserver stop
  2. service vncserver start

And all added users in /etc/vncserver/vncservers.conf will be able to connect via Remote Desktop.

Certainly make sure VNC ports are anebled on the firewall.

Also take in mind that VNC is alsways better to be combined with SSH tunnel as its encryption and vulnerability issues are well known.

Tags

Filed Under: DebianDesktopOperating SystemsServer Administration UtilitiesServer ManagementTutorialsWeb-hosting

Anthony Gee About the Author: Anthony G. is an IT specialist with more than 9 years of solid working experience in the Web Hosting industry. Currently works as server support administrator, involved in consultative discussions about Web Hosting and server administration. One of the first writers in the Onlinehowto.net website, now writing for Free Tutorials community - he is publishing tutorials and articles for the wide public, as well as specific technical solutions.

Leave a Reply