Chinaunix首页 | 论坛 | 博客
  • 博客访问: 678409
  • 博文数量: 180
  • 博客积分: 5851
  • 博客等级: 大校
  • 技术积分: 1946
  • 用 户 组: 普通用户
  • 注册时间: 2005-01-22 22:11
文章分类

全部博文(180)

文章存档

2021年(1)

2019年(2)

2018年(13)

2017年(8)

2016年(1)

2015年(11)

2014年(8)

2012年(18)

2011年(8)

2010年(7)

2009年(10)

2008年(20)

2007年(17)

2006年(39)

2005年(17)

我的朋友

分类: 系统运维

2015-08-16 18:55:13

我使用tightvnc Server/Client,不过无所谓,都通用

安装 sudo apt-get install tightvnc
在/etc/init.d里写入vncserver文件并chomd +x ,方便使用

点击(此处)折叠或打开

  1. export USER="vnc_username" #这里写入用户名,用于设置密码用的
  2. DISPLAY="1"
  3. DEPTH="16"
  4. GEOMETRY="1024x768"
  5. OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"  # 这里注意,加入-localhost参数,是vnc over ssh,不能直接访问端口,必须走ssh
  6. . /lib/lsb/init-functions
  7. case "$1" in
  8. start)
  9. log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
  10. su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
  11. ;;
  12. stop)
  13. log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
  14. su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
  15. ;;
  16. restart)
  17. $0 stop
  18. $0 start
  19. ;;
  20. esac
  21. exit 0
然后执行 $vncpasswd ,会给当前用户增加一个vnc密码,必须做,但不用root

此时会建立一个~/.vnc目录,此刻我们需要编辑一下~/.vnc/xstartup文件,以展示全部的desktop元素:
此时执行一下安装gnome的工作:sudo apt-get install gnome-core 或者 sudo apt-get install ubuntu-desktop

点击(此处)折叠或打开

  1. #!/bin/sh
  2. unset SESSION_MANAGER
  3. unset DBUS_SESSION_BUS_ADDRESS
  4. [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
  5. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
  6. xsetroot -solid grey
  7. DESKTOP_SESSION="ubuntu-2d"; export DESKTOP_SESSION
  8. GDMSESSION="ubuntu-2d"; export GDMSESSION
  9. vncconfig -iconic &
  10. xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
  11. gnome-session &
  12. gnome-panel &
  13. gnome-settings-daemon &
  14. metacity &
  15. nautilus -n &
  16. gnome-terminal &
注意后面执行gnome写了一堆,都需要 :)

执行:sudo service vncserver start

此时还要注意防火墙,使用sudo ufw all 5901 或者sudo iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
然后telnet PUBLIC_IP 5901测试一下



使用tightvnc客户端,直接连上看看。




阅读(689) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~