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
vncpasswd

cat ./vnc/xstartup #no need to modify

#!/bin/sh

unset SESSION_MANAGER

unset DBUS_SESSION_BUS_ADDRESS

exec /etc/X11/xinit/xinitrc

 

vi ~/.vnc/xstartup

    #!/bin/sh
    [ -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

    [Unit]
    Description=Remote desktop service (VNC)
    After=syslog.target network.target

    [Service]
    Type=forking
    User=root

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

    [Install]
    WantedBy=multi-user.target

#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 multi-user.target

PS:

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

 

Good Luck & Best Wishes