Monday, March 27, 2017

RHEL7 - VNC server set up

Access remote systems using ssh and VNC

1. Connect to remove server using ssh, verify you can login
If its windows PC, use putty to connect or
if it is another unix/linux terminal, do the step below.
$ ssh user@remove-server.com
$ ssh sam@192.168.10.20
$ ssh sam@ssbx-lx-v01.expanor.local

2. Install yum server on your remote server
# yum install tigervnc-server

3. Type vncserver at the prompt to start vnc server, will prompt for pw.
# vncserver

Note: vnc uses ports 5900 for service and
5901 and up for each user connection.

4. Connect from Windows computer
- Download vnc viewer. One of the popular one is tiget VNC viewer.
- Once you install, open the app
- use ip and port to connect
192.168.10.20:5901

You will be prompted for password and will have GUI





[root@sgld-lx-v01 ~]# yum list installed | grep tigervnc
tigervnc-license.noarch                 1.3.1-9.el7                @anaconda/7.3
tigervnc-server-minimal.x86_64          1.3.1-9.el7                @anaconda/7.3
[root@sgld-lx-v01 ~]# vnc
vncconfig  vncpasswd
[root@sgld-lx-v01 ~]# yum install -y tigervnc-server
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package tigervnc-server.x86_64 0:1.3.1-9.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                         Arch                   Version                      Repository             Size
=================================================================================================================
Installing:
 tigervnc-server                 x86_64                 1.3.1-9.el7                  LOCAL                 203 k

Transaction Summary
=================================================================================================================
Install  1 Package

Total download size: 203 k
Installed size: 493 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tigervnc-server-1.3.1-9.el7.x86_64                                                            1/1
  Verifying  : tigervnc-server-1.3.1-9.el7.x86_64                                                            1/1

Installed:
  tigervnc-server.x86_64 0:1.3.1-9.el7

Complete!
[root@sgld-lx-v01 ~]# su - devi
Last login: Thu Apr  6 13:43:05 EDT 2017 from 172.16.253.79 on pts/2
[devi@sgld-lx-v01 ~]$ logout
[root@sgld-lx-v01 ~]# cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
[root@sgld-lx-v01 ~]# more /etc/system
systemd/            system-release      system-release-cpe
[root@sgld-lx-v01 ~]# more /etc/systemd/system/vncserver@\:2.service
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Edit /etc/systemd/system/vncserver@.service, replacing <USER>
#    with the actual user name. Leave the remaining lines of the file unmodified
#    (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
#     PIDFile=/home/<USER>/.vnc/%H%i.pid)
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.


[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
[root@sgld-lx-v01 ~]# vi /etc/systemd/system/vncserver@\:2.service
[root@sgld-lx-v01 ~]# firewall-cmd --permanent --zone=public --add-port=5903/tcp
success
[root@sgld-lx-v01 ~]# firewall-cmd --reload
success
[root@sgld-lx-v01 ~]# su - devi
Last login: Thu Apr  6 15:14:08 EDT 2017 on pts/2
[devi@sgld-lx-v01 ~]$ vncserver

You will require a password to access your desktops.

Password:
Verify:

New 'sgld-lx-v01.sces.test:1 (devi)' desktop is sgld-lx-v01.sces.test:1

Creating default startup script /home/devi/.vnc/xstartup
Starting applications specified in /home/devi/.vnc/xstartup
Log file is /home/devi/.vnc/sgld-lx-v01.sces.test:1.log

[devi@sgld-lx-v01 ~]$ logout
[root@sgld-lx-v01 ~]# systemctl daemon-reload
[root@sgld-lx-v01 ~]# systemctl start vncserver@:2.service
Job for vncserver@:2.service failed because a configured resource limit was exceeded. See "systemctl status vncse      

                                                                                                                    

rver@:2.service" and "journalctl -xe" for details.
[root@sgld-lx-v01 ~]# pwd
/root
[root@sgld-lx-v01 ~]# ls -l /etc/systemd/system/vncserver@:2.service
-rw-r--r--. 1 root root 1984 Apr  6 15:19 /etc/systemd/system/vncserver@:2.service
[root@sgld-lx-v01 ~]# systemctl start vncserver@:2.service
Job for vncserver@:2.service failed because a configured resource limit was exceeded. See "systemctl status vncse      

                                                                                                                    

rver@:2.service" and "journalctl -xe" for details.
[root@sgld-lx-v01 ~]# firewall-cmd --permanent --zone=public --add-port=5902/tcp
success
[root@sgld-lx-v01 ~]# systemctl start vncserver@:2.service
Job for vncserver@:2.service failed because a configured resource limit was exceeded. See "systemctl status vncse      

                                                                                                                    

rver@:2.service" and "journalctl -xe" for details.
[root@sgld-lx-v01 ~]# vi /etc/systemd/system/vncserver@:2.service
[root@sgld-lx-v01 ~]# systemctl start vncserver@:2.service
Warning: vncserver@:2.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for vncserver@:2.service failed because a configured resource limit was exceeded. See "systemctl status vncse      

                                                                                                                    

rver@:2.service" and "journalctl -xe" for details.
[root@sgld-lx-v01 ~]# systemctl daemon-reload
[root@sgld-lx-v01 ~]# systemctl start vncserver@:2.service
[root@sgld-lx-v01 ~]# systemctl enable vncserver@:2.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:2.service to /etc/systemd/system/vncs      

                                                                                                                    

erver@:2.service.
[root@sgld-lx-v01 ~]# netstat -an | grep -i 5902
tcp        0      0 0.0.0.0:5902            0.0.0.0:*               LISTEN
tcp6       0      0 :::5902                 :::*                    LISTEN
unix  3      [ ]         STREAM     CONNECTED     365902   @/tmp/.X11-unix/X4
[root@sgld-lx-v01 ~]# systemctl stop firewalld
[root@sgld-lx-v01 ~]# systemctl start firewalld
[root@sgld-lx-v01 ~]# firewall-cmd --permanent --zone=public --add-port=5902/udp
success
[root@sgld-lx-v01 ~]# cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:3.service
[root@sgld-lx-v01 ~]# vi /etc/systemd/system/vncserver@\:3.service
[root@sgld-lx-v01 ~]#  systemctl daemon-reload
[root@sgld-lx-v01 ~]# systemctl start vncserver@:3.service
Job for vncserver@:3.service failed because a configured resource limit was exceeded. See "systemctl status vncse
[root@sgld-lx-v01 ~]# vi /etc/systemd/system/vncserver@:3.service
[root@sgld-lx-v01 ~]# firewall-cmd --permanent --zone=public --add-port=5903/udp
success
[root@sgld-lx-v01 ~]# systemctl start vncserver@:3.service
Warning: vncserver@:3.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for vncserver@:3.service failed because a configured resource limit was exceeded. See "systemctl status vncse
[root@sgld-lx-v01 ~]# firewall-cmd --reload
success
[root@sgld-lx-v01 ~]# systemctl daemon-reload
[root@sgld-lx-v01 ~]# systemctl start vncserver@:3.service
Job for vncserver@:3.service failed because a configured resource limit was exceeded. See "systemctl status vncse
[root@sgld-lx-v01 ~]# ls -l /etc/systemd/system/vncserver@\:*
-rw-r--r--. 1 root root 1984 Apr  6 15:25 /etc/systemd/system/vncserver@:2.service
-rw-r--r--. 1 root root 1882 Apr  6 15:37 /etc/systemd/system/vncserver@:3.service
[root@sgld-lx-v01 ~]# vi /etc/systemd/system/vncserver@:3.service
[root@sgld-lx-v01 ~]# firewall
firewall-cmd          firewall-config       firewalld             firewall-offline-cmd
[root@sgld-lx-v01 ~]# firewall-cmd stop
usage: see firewall-cmd man page
firewall-cmd: error: unrecognized arguments: stop
[root@sgld-lx-v01 ~]# systemctl stop firewalld
[root@sgld-lx-v01 ~]# systemctl daemon-reload
[root@sgld-lx-v01 ~]# systemctl start vncserver@:3.service
Job for vncserver@:3.service failed because a configured resource limit was exceeded. See "systemctl status vncse      

                                                                                                                    

rver@:3.service" and "journalctl -xe" for details.
[root@sgld-lx-v01 ~]# diff /etc/systemd/system/vncserver@:2.service /etc/systemd/system/vncserver@:3.service
42,45c42,43
< #ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
< #PIDFile=/home/<USER>/.vnc/%H%i.pid
< ExecStart=/usr/sbin/runuser -l devi -c "/usr/bin/vncserver %i"
< PIDFile=/home/devi/.vnc/%H%i.pid
---
> ExecStart=/usr/sbin/runuser -l prema -c "/usr/bin/vncserver %i"
> PIDFile=/home/prema/.vnc/%H%i.pid
[root@sgld-lx-v01 ~]# ls -ld /home/prema/
drwx------. 18 prema prema 4096 Apr  6 15:40 /home/prema/
[root@sgld-lx-v01 ~]#

[root@sgld-lx-v01 ~]#
[root@sgld-lx-v01 ~]#
[root@sgld-lx-v01 ~]#
[root@sgld-lx-v01 ~]#
[root@sgld-lx-v01 ~]#
[root@sgld-lx-v01 ~]# pwd
/root
[root@sgld-lx-v01 ~]# vncserver -kill :2

Can't find file /root/.vnc/sgld-lx-v01.sces.test:2.pid
You'll have to kill the Xvnc process manually

[root@sgld-lx-v01 ~]# su - devi
Last login: Thu Apr  6 15:20:31 EDT 2017 on pts/2
[devi@sgld-lx-v01 ~]$
[devi@sgld-lx-v01 ~]$
[devi@sgld-lx-v01 ~]$
[devi@sgld-lx-v01 ~]$ vncserver -kill :2
Killing Xvnc process ID 7918
Xvnc seems to be deadlocked.  Kill the process manually and then re-run
    /bin/vncserver -kill :2
to clean up the socket files.
[devi@sgld-lx-v01 ~]$ ps -ef | grep vnc
devi   6869     1  0 15:20 pts/2    00:00:00 /bin/Xvnc :1 -desktop sgld-lx-v01.sces.test:1 (devi) -auth /ho      

                                                                                                                    

me/devi/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/devi/.vnc/passwd -rfbport 5901 -fp cat      

                                                                                                                    

alogue:/etc/X11/fontpath.d -pn
devi   6874     1  0 15:20 pts/2    00:00:00 /bin/vncconfig -iconic
devi   8665     1  0 15:23 ?        00:00:00 /usr/bin/Xvnc :3 -desktop sgld-lx-v01.sces.test:3 (devi) -auth      

                                                                                                                     

/home/devi/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/devi/.vnc/passwd -rfbport 5903 -fp       

                                                                                                                    

catalogue:/etc/X11/fontpath.d -pn
devi   8670     1  0 15:23 ?        00:00:00 /usr/bin/vncconfig -iconic
devi   9435     1  0 15:23 ?        00:00:00 /usr/bin/Xvnc :4 -desktop sgld-lx-v01.sces.test:4 (devi) -auth      

                                                                                                                     

/home/devi/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/devi/.vnc/passwd -rfbport 5904 -fp       

                                                                                                                    

catalogue:/etc/X11/fontpath.d -pn
devi   9440     1  0 15:23 ?        00:00:00 /usr/bin/vncconfig -iconic
devi  10369     1  0 15:25 ?        00:00:00 /usr/bin/Xvnc :5 -desktop sgld-lx-v01.sces.test:5 (devi) -auth      

                                                                                                                     

/home/devi/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/devi/.vnc/passwd -rfbport 5905 -fp       

                                                                                                                    

catalogue:/etc/X11/fontpath.d -pn
devi  10383     1  0 15:25 ?        00:00:00 /usr/bin/vncconfig -iconic
devi  11097     1  0 15:25 ?        00:00:00 /usr/bin/Xvnc :6 -desktop sgld-lx-v01.sces.test:6 (devi) -auth      

                                                                                                                     

/home/devi/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/devi/.vnc/passwd -rfbport 5906 -fp       

                                                                                                                    

catalogue:/etc/X11/fontpath.d -pn
devi  11175     1  0 15:25 ?        00:00:00 /usr/bin/vncconfig -iconic
prema  14116     1  0 15:36 ?        00:00:00 /usr/bin/Xvnc :7 -desktop sgld-lx-v01.sces.test:7 (prema) -auth      

                                                                                                                     

/home/prema/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/prema/.vnc/passwd -rfbport 5907 -fp       

                                                                                                                    

catalogue:/etc/X11/fontpath.d -pn
prema  14149     1  0 15:36 ?        00:00:00 /usr/bin/vncconfig -iconic
prema  15187     1  0 15:37 ?        00:00:00 /usr/bin/Xvnc :8 -desktop sgld-lx-v01.sces.test:8 (prema) -auth      

                                                                                                                     

/home/prema/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/prema/.vnc/passwd -rfbport 5908 -fp       

                                                                                                                    

catalogue:/etc/X11/fontpath.d -pn
prema  15192     1  0 15:37 ?        00:00:00 /usr/bin/vncconfig -iconic
prema  16235     1  0 15:39 ?        00:00:00 /usr/bin/Xvnc :9 -desktop sgld-lx-v01.sces.test:9 (prema) -auth      

                                                                                                                     

/home/prema/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/prema/.vnc/passwd -rfbport 5909 -fp       

                                                                                                                    

catalogue:/etc/X11/fontpath.d -pn
prema  16246     1  0 15:39 ?        00:00:00 /usr/bin/vncconfig -iconic


[root@sgld-lx-v01 ~]# systemctl start vncserver@:2.service
[root@sgld-lx-v01 ~]# systemctl stop vncserver@:2.service
[root@sgld-lx-v01 ~]# systemctl start vncserver@:2.service

No comments:

Post a Comment