VNC serverの設定方法

CentOS(RHEL)でのVNCサーバ(GNOME対応)の設定方法

 

※viのところは青字部分が修正・追記部分です

※例はrootユーザを許可していますが、無論、非rootユーザを推奨します(真ん中より下にある方法参照)

  1. VNCサーバの設定をする
    ※display番号を1に設定します

    # vi /etc/sysconfig/vncservers
    # The VNCSERVERS variable is a list of display:user pairs.
    #
    # Uncomment the lines below to start a VNC server on display :2
    # as my 'myusername' (adjust this to your own).  You will also
    # need to set a VNC password; run 'man vncpasswd' to see how
    # to do that.  
    #
    # DO NOT RUN THIS SERVICE if your local area network is
    # untrusted!  For a secure way of using VNC, see
    # <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.
    
    # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
    
    # Use "-nohttpd" to prevent web-based VNC clients connecting.
    
    # 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.
    
    # VNCSERVERS="2:myusername"
    # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
    VNCSERVERS="1:root"
    VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp -nohttpd"
  2. VNCの接続パスワードの設定をする

    # vncpasswd
    

    ※各ユーザを設定したい場合は su - ○○ をしてからvncpasswdを走らせる

  3. 一度vncサーバを起動する

    # /etc/rc.d/init.d/vncserver start
    

    ※この状態でvnc接続をするとGNOMEではなく、Window Manager (twm)になってしまいます。(凄くシンプルです)

  4. 何事もなかったかのように一度vncサーバを停止する

    # /etc/rc.d/init.d/vncserver stop
    
  5. 設定するユーザのホームディレクトリ配下に有る、各ユーザvncサーバ設定ファイルを編集します。

    ※rootの場合は以下のとおりですが、普段は/home/ユーザ名/.vnc/xstartup になります

    # vi ~/.vnc/xstartup
    #!/bin/sh
    
    # Uncomment the following two lines for normal desktop:
    
    # unset SESSION_MANAGER
    # exec /etc/X11/xinit/xinitrc
    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 &
    xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    twm &
  6. 再度vncサーバを起動する

    # /etc/rc.d/init.d/vncserver start
    
  7. VNCクライアントから接続します

    ※接続は○.○.○.○:1 になります(○.○.○.○にはIPアドレスが入ります)

    VNCクライアントはREAL VNC(日本語版)等を利用ください

 


念のため、非rootユーザ用のvncserver設定

基本的にrootユーザ(上記)と同じです

  1. VNCサーバの設定をする
    ※今回は、display番号を2に設定します

    # vi /etc/sysconfig/vncservers
    # The VNCSERVERS variable is a list of display:user pairs.
    #
    # Uncomment the lines below to start a VNC server on display :2
    # as my 'myusername' (adjust this to your own).  You will also
    # need to set a VNC password; run 'man vncpasswd' to see how
    # to do that.  
    #
    # DO NOT RUN THIS SERVICE if your local area network is
    # untrusted!  For a secure way of using VNC, see
    # <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.
    
    # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
    
    # Use "-nohttpd" to prevent web-based VNC clients connecting.
    
    # 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.
    
    # VNCSERVERS="2:myusername"
    # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
    VNCSERVERS="2:test"
    VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp -nohttpd"
  2. testユーザにスイッチします

    # su - test
    
  3. VNCの接続パスワードの設定をする

    $ vncpasswd
    
  4. rootに戻ります

    $ exit
    
  5. 一度vncサーバを起動する

    # /etc/rc.d/init.d/vncserver start
    

    ※この状態でvnc接続をするとGNOMEではなく、Window Manager (twm)になってしまいます。(凄くシンプルです)

  6. 何事もなかったかのように一度vncサーバを停止する

    # /etc/rc.d/init.d/vncserver stop
    
  7. 設定するユーザのホームディレクトリ配下に有る、各ユーザvncサーバ設定ファイルを編集します。

    ※testユーザのhomeディレクトリは /home/test/ と仮定します。

    # vi /home/test/.vnc/xstartup
    #!/bin/sh
    
    # Uncomment the following two lines for normal desktop:
    
    # unset SESSION_MANAGER
    # exec /etc/X11/xinit/xinitrc
    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 &
    xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    twm &
  8. 再度vncサーバを起動する

    # /etc/rc.d/init.d/vncserver start
    
  9. VNCクライアントから接続します

    ※接続は○.○.○.○:2 になります(○.○.○.○にはIPアドレスが入ります)

以上の手順でVNCクライアントからdisplay番号2指定で繋がります。

 


複数ユーザ使用時のvncserver設定

基本的に同じです。/etc/sysconfig/vncserversが変わるだけです

  1. /etc/sysconfig/vncserversの設定
    # vi /etc/sysconfig/vncservers
    # The VNCSERVERS variable is a list of display:user pairs.
    #
    # Uncomment the lines below to start a VNC server on display :2
    # as my 'myusername' (adjust this to your own).  You will also
    # need to set a VNC password; run 'man vncpasswd' to see how
    # to do that.  
    #
    # DO NOT RUN THIS SERVICE if your local area network is
    # untrusted!  For a secure way of using VNC, see
    # <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.
    
    # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
    
    # Use "-nohttpd" to prevent web-based VNC clients connecting.
    
    # 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.
    
    # VNCSERVERS="2:myusername"
    # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
    VNCSERVERS="1:root 2:test"
    VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp -nohttpd"
    VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp -nohttpd"
  2. 後は、同様にvncpasswdと起動・xの設定をしてあげるだけです。

    ここから下は脱線。

    個人的にび~ぼ自身は、VNC数度しか繋げたことがないです。

    と、言うのもサーバ自体GUI使う必要も余り無いし(時々必要になる時がある)
    【/etc/inittab】も【id:3:initdefault:】としてランレベル3で走らせてるし、
    管理するならコマンド叩いたほうが早いかなと思います。
    (コマンドを覚えちゃいましょう。)

    GUI使わないといけないアプリとかインストーラの時用かなと。
    例えばOracleとかその手。

    画面呼ぶだけならXming(Xming日本語化プロジェクト)使ったらいいかなとも思えたり。
    (Oracleは文字化けして使えませんでした。まぁ、lang=Cやれば良いんだけどね)

    Xmingも今後若干書こうかな。