Tuesday, May 10, 2016

How to Setup VNCServer on CentOS 7 for Remote Access

VNCServer helps connect to a host remotely, the clients see a graphical interface (typically the desktop manager like GNOME or XFCE or KDE). The following steps can be followed to configure VNCServer on CentOS 7 (and also RHEL7.x).

  • Install the X Window system (if not already there):

    First make sure that yum is configured. You may run the following commands (as root) view and install the X Windows System (GNOME).

    ~]# yum group list
    Installed Environment Groups:
        Server with GUI
    Available Environment Groups:
        Minimal Install
        Infrastructure Server
        File and Print Server
        Basic Web Server
        Virtualization Host
    Available Groups:
        Compatibility Libraries
        Console Internet Tools
        Development Tools
        Graphical Administration Tools
        Legacy UNIX Compatibility
        Scientific Support
        Security Tools
        Smart Card Support
        System Administration Tools
        System Management
    Done

    ~]# yum groupinstall "Server with GUI"

  • Install VNCServer:

    Install the tigervnc-server package, which provides the required VNCServer functionality.

    ~]# yum install tigervnc-server*

  • Setup VNCServer user and Firewall:

    The VNCServer runs at ports starting from 5900 and port identifies a display number. For instance port 5901 indicates VNCServer display :1 which can typically be accessed via hostname/ipaddress:1. If needed these ports should be added to the firewall as well.

    Create a user test which will be used to login from the VNC client.

    ~]# useradd testuser
    ~]# passwd testuser

    Login as testuser and set a password for VNCServer.

    ~]# su - testuser
    ~]$ vncpasswd
    ~]$ logout
    ~]#

    Let us assume that we will be hosting VNCServer at display :1 (port 5901). Add this port to the firewall.

    ~]# firewall-cmd --permanent --zone=public --add-port=5901/tcp
    ~]# firewall-cmd --reload

  • Configure VNCServer at display :1 (port 5901):

    Copy the template service file that came with the VNCServer package to /etc/systemd/system/. Rename the file to indicate display :1.

    ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

    Edit the file with an editor (vim or emacs) and change the <USER> to the testuser we have created above.

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

    [Service]
    Type=forking
    # Clean any existing files in /tmp/.X11-unix environment
    ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
    ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
    PIDFile=/home/<USER>/.vnc/%H%i.pid
    ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

    [Install]
    WantedBy=multi-user.target

    Save the changes made to the file. Now enable the service to run at boot and start the service.

    ~]# systemctl daemon-reload
    ~]# systemctl enable vncserver@:1.service
    ~]# systemctl start vncserver@:1.service

Now use a VNC Client software to connect to the VNCServer running on the host at <hostname>:1.

That's it!

How to Use Beyond Compare 4 as the default Mergetool and Difftool in Git

Beyond Compare 4 is a fantastic tool for comparing a variety of files and view differences in a folder tree. The feature list goes on and on. A tool so powerful as this can also be used as the default difftool and mergetool with Git Version Control system.

The following steps can be run to setup Git to work with Beyond Compare. These work on any operation system i.e., Windows, Linux etc., on Git version higher than 1.8. Ensure that bcomp.exe (Windows) or bcomp (Linux) are in the PATH, i.e., Git can access them from where difftool or mergetool commands are run.

  • Set Beyond Compare 4 as the default difftool

    ~]# git config --global diff.tool bc3
    ~]# git config --global difftool.bc3 trustExitCode true

  • Set Beyond Compare 4 as the default mergetool

    ~]# git config --global merge.tool bc3
    ~]# git config --global mergetool.bc3 trustExitCode true

Now you may run git difftool and git mergetool commands and the Beyond Compare will open up as expected.