[Linux] VNC 설정

■ 리눅스 데스크탑 설치

먼저 리눅스 데스크탑이 설치되어 있어야 vnc를 설치할 수 있습니다.

vnc의 용도가 GUI를 이용하는 데스크탑을 이용하는 것이기 때문에 데스크탑이 설치되어 있지 않다면 의미가 없습니다.

 

RHEL및 CentOS는 Group Install이라는것을 지원합니다. 이것을 이용하여 데스크탑을 설치합니다.

Group Install이라는 이름에서 알 수 있듯이 데스크탑 설치에 필요한 패키지를 자동으로 설치하여 줍니다.

 

▶ 설치가능한 Group List 확인

shell #> yum grouplist
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Determining fastest mirrors
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
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

 

▶ 리눅스 데스크탑을 설치합니다. 반드시 따옴표(")로 묶어줍니다.

참고로 X Window System은 리스트에 보이지 않습니다. 하지만 이것을 포함시켜야 데스크탑을 설치할 수 있습니다.

꽤 많은 패키지들이 설치가 됩니다.

shell> yum groupinstall 'X Window System' 'GNOME Desktop'

 

■ VNC 설치

VNC 패키지를 설치합니다. 참고로 TigerVNC를 설치합니다.

shell > yum install xorg-x11-fonts-Type1.noarch tigervnc-server

 

■ 시스템 방화벽 설정

방화벽을 오픈합니다. 기본적으로 5901, 5902를 열어야 합니다.

참고로 root 이외의 계정 n개를 vnc server 설정한다면 TCP 5901~(5901+n) 범위의 포트를 시스템 또는 네트워크 방화벽 open하여야 합니다.

shell> firewall-cmd --permanent --zone=public --add-port 5901/tcp
success
shell> firewall-cmd --permanent --zone=public --add-port 5902/tcp
success
shell> firewall-cmd --reload
success
shell> firewall-cmd --list-ports
5901/tcp 5902/tcp

 

■ 유저생성

vnc로 접속할 유저를 추가합니다.

shell> useradd -m -s /bin/bash vncuser
shell> passwd vncuser

 

 

 

■ vncserver 설정

▶ 계정에 따른 vnc환경 설정

1. 계정별 환경설정

1.1 root user 수행

shell #> vncserver
You will require a password to access your desktops.


Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used


New 'original:1 (root)' desktop is original:1


Creating default startup script /root/.vnc/xstartup
Creating default config /home/vuser/.vnc/config
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/original:1.log

 

암호입력 - 2번 입력

마지막 질문은 n

 

1.2 vncuser 수행

shell #> su - vncuser
shell $> vncserver
You will require a password to access your desktops.


Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used


New 'original:1 (vuser)' desktop is original:1


Creating default startup script /home/vuser/.vnc/xstartup
Creating default config /home/vuser/.vnc/config
Starting applications specified in /home/vuser/.vnc/xstartup
Log file is /home/vuser/.vnc/original:1.log

 

암호입력 - 2번 입력

마지막 질문은 n

 

2. vncuser의 xtartup 파일 설정 및 퍼미션 변경

root는 /root/.vnc 를 편집합니다.

vncuser는 /home/vncuser/.vnc 를 편집합니다.

shell $> cd .vnc
shell $> mv xstartup xstartup.bak
shell $> vim .vnc/xstartup

 

다음 내용을 입력

#!/bin/sh

vncconfig -iconic &
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 1280x1024 -ls -title "$VNCDESKTOP Desktop" &
#twm &
exec gnome-session &

 

 

3. VNC user별 환경설정

3.1 VNC user별 환경설정을 위해 original VNC config 파일을 계정별 복사

shell $> cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service <-- root용
shell $> cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service <-- vncuser용

 

3.2 VNC 설정.

: root 설정.
shell> vi /etc/systemd/system/vncserver@:1.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target


[Service]
Type=forking
User=root
Group=root


# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i -geometry 1280x1024 > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i -geometry 1280x1024 > /dev/null 2>&1 || :'


[Install]
WantedBy=multi-user.target

 

: vncuser 설정.
shell> vi /etc/systemd/system/vncserver@:2.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target


[Service]
Type=forking
User=vncuser
Group=vncuser


# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i -geometry 1280x1024 > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l vncuser -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/home/vncuser/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i -geometry 1280x1024 > /dev/null 2>&1 || :'


[Install]
WantedBy=multi-user.target

 

■ 시스템 설정 reload

shell #> systemctl daemon-reload

 

 

 

■ vnc service를 enable & start

shell #> systemctl enable vncserver@:1.service
shell #> systemctl enable vncserver@:2.service
shell #> systemctl start vncserver@:1.service
shell #> systemctl start vncserver@:2.service

 

■ vnc service에 의한 포트 listen 여부 확인(tcp 5901, 5902, 6001, 6002)

shell #> netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      2736/Xvnc
tcp        0      0 0.0.0.0:5902            0.0.0.0:*               LISTEN      2924/Xvnc
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      2736/Xvnc
tcp        0      0 0.0.0.0:6002            0.0.0.0:*               LISTEN      2924/Xvnc
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      792/sshd
tcp6       0      0 :::6001                 :::*                    LISTEN      2736/Xvnc
tcp6       0      0 :::6002                 :::*                    LISTEN      2924/Xvnc
tcp6       0      0 :::22                   :::*                    LISTEN      792/sshd
shell #>

 

 

■ vnc 클라이언트로 접속

다음의 사이트에서 viewer를 다운로드 합니다.

 

Download VNC Viewer | VNC® Connect

 

www.realvnc.com

다운로드 후 설치를 합니다. 일반 설치 프로그램과 같습니다.

 

설치 후 vnc viewer를 실해압니다.

그리고 vnc viewer에서 접속을 시도합니다.

1. root -> <ip address>:1

2. vncuser -> <ip address>:2

 

■ 참고 : 명령어들

▶ vnc서버 리스트 확인

vncserver -list

 

▶ vnc 프로세스 리스트 Kill

 killall Xvnc

 

 

※도움이 되셨다면 광고클릭 한번 부탁드립니다.※

Designed by JB FACTORY