Page 1 of 1

VNC Server configuration

Posted: 2023 May 03, 19:37
by Mihai
Install the necessary packages for VNC Server

Code: Select all

[root @ centos ~]$ yum install vnc-server
[root @ centos ~]$ yum groupinstall Desktop
Add the users we want to receive access to the VNC Server

Code: Select all

[root @ centos ~]$ sudo su -
[root @ centos ~]$ useradd user1
[root @ centos ~]$ useradd user2
[root @ centos ~]$ useradd user3
[root @ centos ~]$ passwd user1
[root @ centos ~]$ passwd user2
[root @ centos ~]$ passwd user3
Edit configuration file for VNC Server and add the settings for users

Code: Select all

[root @ centos ~]$ vi /etc/sysconfig/vncservers
VNCSERVERS="1:user1 2:user2 3:user3"
VNCSERVERARGS[1]="-geometry 640x480"
VNCSERVERARGS[2]="-geometry 640x480"
VNCSERVERARGS[3]="-geometry 800x600"
Add user1 password to VNC Server

Code: Select all

[root @ centos ~]$ su - user1
[user1 @ centos ~]$ vncpasswd
[user1 @ centos ~]$ cd .vnc
[user1 @ centos .vnc]$ ls -a
passwd
Start and Stop the VNC server to check for errors

Code: Select all

[root @ centos ~]$ /sbin/service vncserver start
[root @ centos ~]$ /sbin/service vncserver stop
Add the VNC Server to startup

Code: Select all

[root @ centos ~]$ /sbin/chkconfig vncserver on
Check if the configuration file for the user (in our case it is user1) is created
In this case the configuration presents a gnome session

Code: Select all

[root @ centos ~]$ nano /home/user1/xstartup
#!/bin/sh
[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
vncconfig SecurityTypes=RA2
vncconfig RSA_Private_Key_File=$HOME/.vnc/private.key
vncconfig UserPasswdVerifier=UnixAuth
vncconfig AllowedUsers=cio:f
vncconfig AllowedGroups=staff:d
vncconfig QueryConnect=2
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
case "$WINDOWMANAGER" in
*gnome*)
if [ -e /etc/SuSE-release ]; then
PATH=$PATH:/opt/gnome/bin
export PATH
fi
;;
esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
exec /etc/X11/xinit/xinitrc
fi
if [ -f /etc/X11/xinit/xinitrc ]; then
exec sh /etc/X11/xinit/xinitrc
fi
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
exec gnome-session
Add rule in firewall to allow connection to VNC Server

Code: Select all

[root @ centos ~]$ iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 5900,5901 -j ACCEPT
Start VNC Server

Code: Select all

[root @ centos ~]$ /sbin/service vncserver start