• VNC连接远程Ubuntu设置


    一.windows 远程软件VNCViewer

    这个不多说: 下载地址:http://www.realvnc.com/download/viewer/

    二.安装 vnc-server

    红帽的rpm系安装使用 

    yum install tigervnc-server

    debian 的deb系安装使用

    apt-get install vnc4server

    再次安装失败, 提示:

    404  Not Found [IP: 112.124.140.210 80]
    Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libx11/libx11-xcb1_1.4.99.1-0ubuntu2.2_amd64.deb  404  Not Found [IP: 112.124.140.210 80]
    Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libxfixes/libxfixes3_5.0-4ubuntu4.2_amd64.deb  404  Not Found [IP: 112.124.140.210 80]
    Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libxi/libxi6_1.7.1.901-1ubuntu1~precise1_amd64.deb  404  Not Found [IP: 112.124.140.210 80]
    Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libxv/libxv1_1.0.6-2ubuntu0.1_amd64.deb  404  Not Found [IP: 112.124.140.210 80]
    Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/x/x11-utils/x11-utils_7.6+4ubuntu0.1_amd64.deb  404  Not Found [IP: 112.124.140.210 80]
    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

    提示让apt-get update , update后

    apt-get install vnc4server 

    就ok了。

     

    三. 修改VNC Password

    vncpasswd

    Password: ******
    Verify:*****

    如果输入vncpasswd 提示 : bash: vncpasswd: 未找到命令, 估计用的是yum 的  yum install vnc-server    记得是tigervnc-server哦。

    四.启动VNC server

    vncserver

    提示:

    xauth:  file /root/.Xauthority does not exist
    New 'AYbZ:1 (root)' desktop is AYbZ:1
    Creating default startup script /root/.vnc/xstartup
    Starting applications specified in /root/.vnc/xstartup
    Log file is /root/.vnc/AYbZ:1.log

    五.连接vnc

    客户端连接vnc 使用端口为:1 每启动一次vncserver 相应的:端口就会变化一次

    在这里,我们看到的是一个Linux命令行窗口

    六.修改显示界面

    我们打开/root/.vnc/xstartup

    vim /root/.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 &
    x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    x-window-manager &

    我们需要将最后一行“x-window-manager &”改为我们自己的Ubuntu图形界面服务, Ubuntu有gnome、KDE、Unity等桌面环境。
    如果是gnome桌面,改成gnome-session &
    如果是KDE桌面,改成startkde &
    如果是Unity桌面,首先去 /usr/share/gnome-session/sessions/下看桌面session的名称,如果是ubuntu-2d,则将最后一行改为:
    export STARTUP="/usr/bin/gnome-session --session=ubuntu-2d"
    $STARTUP

    ------------------------

    在这里,一大波问题来袭

    修改最后一行为:gnome-session & 

    重启vnc:

    vncserver -kill :1
    vncserver

    vnc还显示命令行窗口

    好,我们知道,有可能是没有安装桌面环境。方法安装:

    第一步:安装x-windows的基础

    apt-get install x-window-system-core

    第二步:安装登录管理器

    apt-get install gdm

    第三步:安装桌面

    apt-get install ubuntu-desktop

    重启vnc:

    vncserver -kill :1
    vncserver

    依旧显示命令行窗口

    打开配置中默认桌面(去掉配置中的#)

    unset SESSION_MANAGER
    exec /etc/X11/xinit/xinitrc

    理论上是可以了。 如果继续无法看到桌面继续向下看:

    记得在启动vncservier时生成个日志.log文件。

    查看日志文件

    cat root/.vnc/AYbZ:1.log 

    显示如下错误:

    error opening security policy file /etc/X11/xserver/SecurityPolicy
    Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
    Could not init font path element /usr/share/fonts/X11/75dpi/, removing from list!
    Could not init font path element /usr/share/fonts/X11/100dpi/, removing from list!

    我们安装字体便是

    apt-get  install xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic

    安装完成时候,重启vncserver,再次查看log日志文件

    Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!

    /usr/share/fonts/X11目录下有字体文件了,但/usr/X11R6/lib 目录还是不存在字体

    我们可以让X11R6里面软链接到share/fonts字体目录中

    mkdir -r  /usr/X11R6/lib   # 没有X11R6/lib 目录
    cd /usr/X11R6/lib/
    ln -s /usr/share/fonts/X11 X11

    再次重启vncserver

    OK!

    补充

    在内存寸土寸金的服务器端,桌面环境占用越少越好。Ubuntu-desktop至少400MB。发现了好用的xfce,安装好仅占用180MB内存。

    apt-get install xfce4

    编辑~/.vnc/xstartup,添加:

    sesion-manager & xfdesktop & xfce4-panel &
    xfce4-menu-plugin &
    xfsettingsd &
    xfconfd &
    xfwm4 &

    通过ssh端口转发加密VNC连接

    VNC直接连接服务器,在一网段的计算机有可能用wireshark/sniffer窃听到用户名和密码,可以通过SSH进行加密端口映射来保证传输用户名和密码的时候也是加密

    ssl -L 参数: -L 远程端口:本地IP:本地端口  远程user@远程IP
    ssh -L 5901:localhost:5901 useroot@120.55.65.20*

    客户端:

    vncviewer localhost:1

    通过wireshark可以看到用SSH协议进行了加密传输。

    设置vnc分辨率大小

    vncserver -geometry 1440x900

    自定义vnc的连接端口号

    配置文件路径

    which vncserver
    file /usr/bin/vncserver

    修改vncserver文件的内容:

    $geometry = "1024x768";
    $vncPort = 5900 + $displayNumber;

    改为自定义分辨率、端口号:

    $geometry = "1440x900";
    $vncPort = 12012 + $displayNumber;

    vnc的port是端口号+1display number的,所以此时桌面1的端口号就为12013; 重启vncserver。 客户端连接时IP+port, 

    192.168.1.125:12013
  • 相关阅读:
    “贴身外教”是英语口语的学习方法综合解决方案
    浅谈提高英语口语的最有效方法
    【PERL】Perl默认的内部变量
    Perl——哈希的创建和引用
    linux和windows下,C/C++开发的延时函数,sleep函数
    linux标准库#include <unistd.h>与windows的#include <windows.h>(C语言开发)
    linux 如何显示一个文件的某几行(中间几行)
    使程序在Linux下后台运行
    Perl中关于数组的输出——需要注意的地方
    linux下C/C++,多线程pthread
  • 原文地址:https://www.cnblogs.com/dcb3688/p/4607962.html
Copyright © 2020-2023  润新知