vncserver setup on OEL7 linux

#more info about vncserver on OEL7 is here

#disable firewalld
systemctl stop firewalld
systemctl disable firewalld

yum groupinstall "server with gui" -y
yum install tigervnc-server -y
yum install gnome-terminal gnome-session -y

su - root

cat ./vnc/xstartup #no need to modify




exec /etc/X11/xinit/xinitrc


vi ~/.vnc/xstartup

    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    gnome-terminal &
    gnome-session &

chmod 755 ~/.vnc ; chmod 600 ~/.vnc/passwd ; chmod 755 ~/.vnc/xstartup
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver-root@\:1.service

vi /etc/systemd/system/vncserver-root@\:1.service

    Description=Remote desktop service (VNC)


    # Clean any existing files in /tmp/.X11-unix environment
    ExecStartPre=-/usr/bin/vncserver -kill %i
    ExecStart=/usr/bin/vncserver %i
    ExecStop=-/usr/bin/vncserver -kill %i


#Optionally, you can add command-line arguments for the VNC server 
    (only accepts connections from localhost, and change size of the window)

ExecStart=/sbin/runuser -l vncuser -c "/usr/bin/vncserver %i -geometry 1600x900" #this is only for root user

ExecStart=/usr/bin/vncserver %i -geometry 1600x900 #this is for normal user

systemctl daemon-reload #if changing vnc config, must run this afterwards

systemctl start vncserver-root@\:1.service
systemctl enable vncserver-root@\:1.service

systemctl get-default #make sure it's


Here is more info about vncserver usage:

To create a session

    vncserver -geometry 1600x900 :4

Edit .vnc/xstartup: Replace twm with gnome-session

Then kill the current VNC session and create a new one (run as the user who starts the session)

    vncserver -kill :4
vncserver -geometry 1600x900 :4

For one time vnc, you can run below:

vncserver -geometry 1600x900 :1 #this will create a vnc session in ":1", screen resolution will be 1600x900

vncpasswd #set vnc password for above session

Then connect to vnc the_hostname:1

Good Luck & Best Wishes