转自:http://nuclear-imaging.info/site_content/2011/05/11/vnc-server-setup-for-ubuntu-11-04-natty-narwhal/
For the first time I was able to get VNC to work with Ubuntu with Gnome session instead of a xterm on gray background. The steps involved were exactly the same as I was following earlier, with one exception: the setup of xstartup in the ~/.vnc folder.
For your xstartup file in ~/.vnc (the “.vnc” folder in
your home directory), you need the following:
#—————————–
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
扫描二维码关注公众号,回复: 5625687 查看本文章# 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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
gnome-session &
# twm &
#————————
instead of uncommenting the lines as the script suggests, you change the window manager to gnome-session
make sure restart vnc4server
The line which got Gnome working was “gnome-session &”
========================================
Now for all the steps involved (works in Karmic Koala Alpha 2, Ubuntu 9.10, kernel 2.6.30-10)
1. Install ssh server, ssh client, VNC viewer, VNC server, and xinetd
sudo apt-get install openssh-server openssh-client vnc4server xinetd vncviewer
2. Setup the ssh password for your login
ssh-keygen
3. Test out the ssh server by typing in
ssh localhost or ssh your_login@your_ip_address
4. Then create a vnc password
sudo vncpasswd ~/.vncpasswd
5. Edit the xstartup file in ~/.vnc directory
For your xstartup file in ~/.vnc (the “.vnc” folder in
your home directory), you need the following:
—————————–
#!/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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
gnome-session &
# twm &
————————
instead of uncommenting the lines as the script suggests, you change the window manager to gnome-session
6. Create a VNC desktop
vnc4server :1 -geometry 1024×768
7. Then to tunnel into your VNC desktop, first create a SSH tunnel by logging into SSH with the comand:
ssh -L 5901:your_ip_address:5901 your_username@your_ipaddress
8. Finally, load up your VNC desktop
vncviewer localhost:1