How to restrict per user vnc sessions count ?
Environment
- Red Hat Enterprise Linux 7
- TigerVnc
Issue
- Restrict user's to use only one or a specific count of VNC sessions.
- Multiple VNC sessions affect the systems performance.
Resolution
DISCLAIMER: The following information has been provided by Red Hat, but is outside the scope of the posted Service Level Agreements and support coverage. Such changes are unsupported and have not been gone through extensive testing. You would need to test and confirm in your environment. Also note that tigervnc-server package update would replace the changes.
The information is provided as-is and any configuration settings or installed applications made from the information in this article could make the Operating System unsupported by Red Hat Global Support Services. The intent of this article is to provide information to accomplish the system's needs. Use of the information in this article at your own risk.
- Xvnc does not have executables which could restrict the number of VNC sessions accessible per user.
- Hence, to get the Xvnc to restrict the number of VNC sessions a simple tweak is to be performed to 'usr/bin/vncserver'.
- To accomplish this write a perl script by adding a subroutine check for active vnc sessions for the user and restrict it to 1 or as desired.
- Below is the script to restrict the VNC sessions per user :
$ vi /usr/bin/vncserver
301 # Now start the X VNC Server
302
303 # Maximum session limit to 1 per user.
304 &vnclimit();
305
890 }
891 }
892
893 sub vnclimit {
894 $countoutput = `ps -u $ENV{USER} | grep -i Xvnc | wc -l`;
895 if ($countoutput >= 1) {
896 print "You are already running a VNC session for $ENV{USER} user. Maximum session is limited to 1 per user!\n";
897 print "Run 'vncserver -list' to list the current session\n\n";
898 print "Please contact your System Administrator for more details.\n";
899 exit;
900 }
901 }
EXAMPLE
$ vncserver
You are already running a VNC session for deepu user. Maximum session is limited to 1 per user!
Run 'vncserver -list' to list the current session
Please contact your System Administrator for more details.
$ vncserver -list
TigerVNC server sessions:
X DISPLAY # PROCESS ID
:3 32621
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments