A while back, I read an interesting article Enable multiuser logins with VNC – Help your users access a multiuser Linux system from anywhere on IBM developerWorks. I was thinking it could be used to implement something similar to the terminal service in Windows. There are many good use cases for terminal services. I think you probably know better than I do so I skip this part.
I finally got a bit time to give it a try but didn’t succeed the first time with CentOS 6.4. It’s not that the author had anything wrong, but that the there are too many flavors of Linux and the author can only touch some for each flavor.
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
The idea behind the article is simple – use the X Display Manager Control Protocol (XDMCP) behind the VNC server. To enable the XDMCP, you just need to change the settings. While there are 3 samples given in the developerWorks article, I could find none of them applicable on CentOS.
Well, Internet is abundant of information. After a bit search, I found you can change the configuration as follows on CentOS:
# vim /etc/gdm/custom.conf [xdmcp] Enable=true # telinit 3 # telinit 5
After that, it still did not work. More search got me this forum discussion. Whatever the author tried with an older version a while back still works in CentOS 6.4.
The command is really to run the Xvnc so that it starts to listen on a particular port. By default, VNC server uses 5900, in short form 0. There could be multiple processes on different ports. To support multi-users, you will need equal number of ports open. In my case, I tried port 8 (5908) and 9 (5909). To be sure, you can use ps command to verify.
# /usr/bin/Xvnc :8 -query localhost -geometry 1100×850 -securitytypes none & # ps aux | grep Xvnc root 19107 0.1 0.0 97488 36036 pts/5 S 16:35 0:02 /usr/bin/Xvnc :8 -query localhost -geometry 1100?850 -securitytypes none root 19958 0.3 0.0 97956 36236 pts/5 S 16:53 0:01 /usr/bin/Xvnc :9 -query localhost -geometry 1100?850 -securitytypes none
After the server is ready, you can find another machine with VNC client (also called viewer) installed. If not yet, you can easily install it. On CentOS, the command is
# yum install vnc
From VNC client, you just use servername:8 or servername:9, for example, 192.168.23.22:8. Optionally, you can specify absolute port number as 192.168.23.22:5908. On VNC client, you would see a login screen for you to enter username/password.
While one VNC session is going on and another client wants to connect to the same port, the existing VNC client would be kicked away. It’s better than silently sharing the screen on both, but still not quite convenient as it should be. One quick solution to this problem is to block the new client based on IP address with firewall, which may still be a problem for multi-user client, or machines behind a NAT router.
Better solution would be let the server not disconnecting the existing client. After a bit more research, I found one solution from this page – all you need is to add the following argument to the command line.
You can of course have other choices, like –alwaysshared, -nevershared, -viewonly. These are self explanatory.