過去 vnc190715
VNC(Virtual Network Computing)
RFB Protocol(remote framebuffer)を使ってリモートアクセスを可能にする。なのでRFBを受信するサーバアプリと送信するクライアント(ビューア)が揃えばいい代物。
例えば、サーバをwindowsPCで動かして、ビューアをLinuxで動かせば、Linuxからwindowsを操作可能となる。
ここではLinuxでサーバを動かして、windowsから操作してみます。
留意
ここでは、Linuxへのログインユーザが個別にサーバアプリを起動して、ビューアを招き入れる方法を記載します。
XDMCPで繋ぐにはvnc/XDMCP
vnc/noVNC
VNCサーバ †
まず、vncサーバを動かすマシンはグラフィカルモードであること
[root@c ~]# systemctl get-default
graphical.target
[root@c ~]#
そして、vncのサーバアプリをインストールします(既にインストールされているかもしれないけど)
[root@c ~]# yum install tigervnc-server
以上はroot権限の作業。
次にtelnet/sshなりで対象マシン(vncサービスを提供するマシン)にログインしたユーザが、
1.vnc接続のためのパスワードを作成
2.vncサーバを起動します
vnc接続のためのパスワード作成 †
[illya@c ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
[illya@c ~]$
vncサービスを起動 †
場面サイズ1024x1024を作り出してみた
画面番号を1としています。
[illya@c ~]$ vncserver -geometry 1024x1024 :1
New 'c.sybyl.local:1 (illya)' desktop is c.sybyl.local:1
Creating default startup script /home/illya/.vnc/xstartup
Creating default config /home/illya/.vnc/config
Starting applications specified in /home/illya/.vnc/xstartup
Log file is /home/illya/.vnc/c.sybyl.local:1.log
[illya@c ~]$
停止は画面番号とともに指定します。
[illya@c ~]$ vncserver -kill :1
Killing Xvnc process ID 26764
[illya@c ~]$
これでvncサービスは停止します。
っで、vncサービスを稼働したまま、クライアントから接続してみます
vncビューアでアクセス †
先ほどは画面番号1でサービスを起動しました。
この画面番号はクライアントから接続する際のポート番号に連携されます。
画面番号1は5901番、2なら5902番となります。

*ここではUltraVNCを使ってます
Connectボタンを押下すると、先ほど定義したパスワードが聞かれます。

パスワードを入力して、認証されると画面が表示されます。

以上で完了。
作業し終えたら、ビューアを閉じて、「vncserver -kill」で正しく終了しましょう。
この操作を行わないと対象マシンにX関係のプロセスがずっと残ります。
ubuntu18.04 †
基本は「設定」の「共有」から画面共有設定ができるみたい。っが、netplan経由でないと使えないの?
参照先 https://www.cyberciti.biz/faq/install-and-configure-tigervnc-server-on-ubuntu-18-04/
ディスプレイマネージャGDMをそのまま使うには下記 vnc サーバをインストールします。
root@ubuntu-esxi:~# apt install tigervnc-standalone-server tigervnc-xorg-extension
次にvnc経由で画面共有をさせたいユーザの vnc 接続の際に使用するパスワードを決めます。
illya@ubuntu-esxi:~$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
illya@ubuntu-esxi:~$
そしてXセッションの起動用のプログラムを記載します。
illya@ubuntu-esxi:~$ cat .vnc/xstartup
#!/bin/sh
# Start Gnome 3 Desktop
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &
illya@ubuntu-esxi:~$
その後にvncサービスを起動します。
「vncserver -localhost no -geometry 1024x1024 :1」
illya@ubuntu-esxi:~$ vncserver -localhost no -geometry 1024x1024 :1
/usr/bin/xauth: file /home/illya/.Xauthority does not exist
/usr/bin/xauth: (argv):1: bad display name "ubuntu-esxi.sybyl.local:1" in "add" command
/usr/bin/xauth: file /home/illya/.Xauthority does not exist
New 'ubuntu-esxi.sybyl.local:1 (illya)' desktop at :1 on machine ubuntu-esxi.sybyl.local
Starting applications specified in /etc/X11/Xvnc-session
Log file is /home/illya/.vnc/ubuntu-esxi.sybyl.local:1.log
Use xtigervncviewer -SecurityTypes VncAuth,TLSVnc -passwd /home/illya/.vnc/passwd ubuntu-esxi.sybyl.local:1 to connect to the VNC server.
illya@ubuntu-esxi:~$
この段階で「ps」コマンドでプロセスを確認するとユーザのXログインセッションに必要なプロセスが稼働しています。
ここでvncクライアントでアクセスします。

終了方法
illya@ubuntu-esxi:~$ vncserver -kill :1
これにて「vncserver」で起動したプロセスがすべて終了します。
「~/.vnc/xstartup」ファイルを用意しないとプロセスが残りますので要注意
留意
ここでは tiger-vncを使っている。vncserverといっても
illya@ubuntu-esxi:~$ update-alternatives --display vncserver
vncserver - auto mode
link best version is /usr/bin/tigervncserver
link currently points to /usr/bin/tigervncserver
link vncserver is /usr/bin/vncserver
slave vncserver.1.gz is /usr/share/man/man1/vncserver.1.gz
/usr/bin/tigervncserver - priority 80
slave vncserver.1.gz: /usr/share/man/man1/tigervncserver.1.gz
illya@ubuntu-esxi:~$
と「tigervncserver」へリンクされています。
ubuntuメモ †
ubuntuのGNOMEとtigervncはOKみたい。しかしGNOMEとvnc4serverは無理みたい。
ubuntu xfce4 でvnc †
GNOMEが重いなら軽量のディスプレイマネージャで。
こちらを採用されている方が多いのかな
root@ubuntu-esxi:~# apt install xfce4 xfce4-goodies
使用するvncはtigervnc。どうもvnc4serverだと上手く動かない。。こちらだけなのかもしれないけど。
xstartupファイルは
illya@ubuntu-esxi:~$ cat .vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
illya@ubuntu-esxi:~$
