Thursday, March 11, 2010

VNC and multi-user environment in Ubuntu 9.10

To allow multiple users connect to our Ubuntu box, we need to install VNC Server with following commands:
sudo apt-get install vnc4server
It allows to use different sessions for multiple logins, so users can be separated from each other and won't fight for mouse as well as they won't see applications of each other :-)
Then we need to assign a password to our VNC logins. It can be done through running this command:
vncpasswd
Then we can launch a test desktop by running:
vncserver :1
Number here is a display number. Local user runs display :0 etc.
Now we can connect to it, by specifying either port number (::5901) or display number (:1) in remote VNC viewer. However, after logging in, the desktop won't be as usual X session. It will be presented as simple GUI with command line or just as a blank screen with cursor in form of cross.
Now we need to shutdown the session  with:
vncserver -kill :1
Next, edit ~/.vnc/xstartup. It should look similar to:
#!/bin/sh

# Uncomment the following two lines for normal desktop:
#unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc

#[ -x /etc/vnc/xstartup ] && sh /etc/vnc/xstartup
#[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &

unset SESSION_MANAGER
sh /etc/X11/xinit/xinitrc

Now we can start the vncserver :1 again and connect to it. Pay attention to user, under which vncserver have been started. It means, that if we have started server under our current user, the remote login will be as the same user.
To enable different user to log in, we should create another user in Ubuntu, install SSH server and make all the steps from above. Then we can first SSH to our Ubuntu box, log in under different user (which we want to use for our remote VNC session), in console session type vncserver :[number] and then launch vnc viewer on remote client and connect to the session just created.

To secure traffic on it's way, we can tunnel it through the SSH connection. For this we need to add SSH tunnel at the Putty menu by specifying source port as "5900" (if we are connecting to display :0) and destination "localhost:5900". Then connect to the server and leave Putty screen as is. Now we just need to connect via VNC to localhost:5900 and our traffic will be tunneled to SSH connection. That's it.


Whew, sounds like a lot of routine, but I haven't found the way to automate it yet.
The good thing is that at least it's working  ;-)

P.S. To get multiple instance of Firefox (or any other Mozilla application) running simultaneously when we logged on the same user as local session, we need to set the environment variable MOZ_NO_REMOTE=1 before starting Firefox.
To do this just use:
export MOZ_NO_REMOTE=1

No comments:

Post a Comment