wiki:TipAndDoc/network/vnc

vncserver

xstartup

  • gnomeを自動で立ち上げる
    • コンソールのgnomeセッション(実機のtty)とは別に立ち上がる
  • ~/.vnc/xstartup
    • .vnc/xstartup

      old new  
      77[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup 
      88[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources 
      99xsetroot -solid grey 
      10 vncconfig -iconic & 
      11 x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 
      12 x-window-manager & 
       10# vncconfig -iconic & 
       11# x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 
       12# x-window-manager & 
       13exec gnome-session & 
  • $ vncserver :1 -geometry 800x600 -depth 24 -localhost -nolisten tcp
    • Log Outすると……
  • gnomeからログアウトしても自動で再起動するようにする
    #!/bin/sh
    
    # Uncomment the following two lines for normal desktop:
    # unset SESSION_MANAGER
    # exec /etc/X11/xinit/xinitrc
    
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    # vncconfig -iconic &
    # x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    # x-window-manager &
    
    PIDFILE="$HOME/.vnc/*${DISPLAY}.pid"
    
    while :
    do
        [ -r $PIDFILE ] || break
        PID=`cat $PIDFILE`
        ps $PID > /dev/null 2>&1 || break
        
        gnome-session
    done
    
    • 単純にwhile true gnome-sessionだと、vncserver -killしたあとでwait無しの無限ループに入って暴走する
    • ログアウトしてもgnome-screensaverなどのプロセスが残るが、vncserver -kill後に「gnome-screensaver: Fatal IO error 11 (Resource temporarily unavailable) on X server :1.0.」などで死ぬ
    • こちらも、Ubuntu 12.04では、次のようにする必要がある
      • gnome-session --session=gnome-classic

12.10 and later

  • gnome-panelの実行が、gnome-sessionとは別に必要になった
  • ~/.vnc/xstartup
    #!/bin/sh
    
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    gnome-session --session=gnome-classic &
    gnome-panel &
    

12.04 with lxde

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
# vncconfig -iconic &
# x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# x-window-manager &

PIDFILE="$HOME/.vnc/*${DISPLAY}.pid"


vncconfig -nowin &
while :
do
    [ -r $PIDFILE ] || break
    PID=`cat $PIDFILE`
    ps $PID > /dev/null 2>&1 || break
    
    lxsession -s LXDE
done

Arch Linux with LXDE

  • ~/.vnc/xstart
    #!/bin/sh
    
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    
    /usr/bin/startlxde
    
    • デフォルトのxstartexec /etc/X11/xinit/xinitrcによりxclock, xtermなど不要なものを起動するうえ、twmを起動しようとするので修正が必要
  • vncserver :0 -geometry 800x600 -depth 24 -nolisten tcp

x11vnc

  • 「caught XIO error」というエラーとともに勝手にログアウト(Xのセッションからも)することがあるが、詳細不明
  • ~/.x11vncrc
    display :0 # This will do in most single user machine
    rfbauth .vnc/passwd # password file
    rfbport 5900 # Use this default port
    forever # Without this x11vnc will die after serving one connection.
    localhost # Only accept local connections. This makes your x11vnc secure along with SSH.
    
  • x11vnc -storepasswd で作られるパスワードファイルは先頭8文字しか見ない模様
    • -rw------- 1 mitty mitty 8 Feb 17 00:04 .vnc/passwd
  • ssh 越しにx11vnc serverの起動には成功せず(原理的に出来ない?)
    • sudo x11vncで起動すればよい
    • 「alias sudo='sudo -H '」している場合は、以下のようにする
      sudo x11vnc -rc ~/.x11vncrc
      
    • see also ssh
  • xfceの Settings -> Session and Startup の Application Autostart に 「/usr/bin/x11vnc」で登録すると良い
  • ps wwwwaux | grep auth
    root      1106  0.0  3.4 119100 17436 tty7     Ss+  Mar06   0:05 /usr/bin/X :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-bcQe9Q/database -nolisten tcp vt7
    
    • Xfce4 の例
    • -display :0 -auth guess で自動的に見つけてくれる模様

vnc with xinetd

  1. $ sudo aptitude install -R xinetd
  2. $ sudo vim /etc/xinetd.d/x11vnc
    • source:lab/trunk/TipAndDoc/xinetd.d/x11vnc
    • attachment:x11vnc.log <- /var/log/x11vnc.log
      • session毎に上書きされる模様(最新の接続情報しか残らない)
    • この設定では、xinetdとx11vncの両方で、localhost以外からの接続を拒否しているが、それでもxinetdへのセッションそのものは確立するため、iptablesでポートごと塞ぐのがmore better
Last modified 7 years ago Last modified on Oct 9, 2016 11:22:11 PM

Attachments (4)

Download all attachments as: .zip