3流プログラマのメモ書き

元開発職→社内SE→派遣で営業支援の三流プログラマのIT技術メモ書き。 このメモが忘れっぽい自分とググってきた技術者の役に立ってくれれば幸いです。(jehupc.exblog.jpから移転中)

(Linux)VNCサーバ構築

WindowsのクライアントからLinuxサーバ(CentOS5)をVNCでリモートする方法です。

VNCサーバ自体は CentOS インストール時に含めていました。

VNCサーバの起動方法は3つほどあるようです。

1.コマンドで vncserver を起動。

2.起動スクリプト /etc/rc.d/init.d/vncserver を使う方法。

3.inetd を使う方法。

今回は1回ぽっきりの使用だったので 1. の vncserver 手動起動の方法にしました。

まず、XwindowがつかるようにVNCで利用したいユーザの /home/user/.vnc/xstartup で unset と exec のコメントアウトを除けます。

vi /home/user/.vnc/xstartup

#!/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 &

xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

twm &

つぎに、SSHでサーバにログインし、VNCで利用したいユーザで下記のようにコマンドを押下します。

# vncserver

↓初回はパスワードを求められます。

You will require a password to access your desktops.

Password:

Verify:

xauth: creating new authority file /home/hoge/.Xauthority

↓デスクトップ番号2が割り当てられています。

New 'testserver:2 (hoge)' desktop is testserver:2

Creating default startup script /home/hoge/.vnc/xstartup

Starting applications specified in /home/hoge/.vnc/xstartup

Log file is /home/hoge/.vnc/testserver:2.log

後はクライアントから、サーバ名:ディスプレイ番号 で接続するだけです。

サーバ側で vnc を終了するには下記コマンドでできるようです。

# vncserver -kill :ディスプレイ番号

参考:

VNC で Linux サーバにログインする