VNC使用總結

  • 2019 年 12 月 25 日
  • 筆記

這是一些使用VNC連接服務器的總結,這些操作都是在Ubuntu操作系統下進行的。

VNC使用 Gnome桌面系統

安裝Gnome桌面:

sudo apt-get install --no-install-recommends ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

然後修改你的~/.vnc/xstarup文件為如下內容:

#!/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 &    gnome-panel &  gnome-settings-daemon &  metacity &  nautilus -n &  gnome-terminal &

使用Xfce桌面

如果要使用xfce桌面的話,通過如下命令來安裝:

sudo apt install xfce4 xfce4-goodies

然後將~/.vnc/xstartup改為如下:

#!/bin/bash  xrdb $HOME/.Xresources  startxfce4 &

打開gnome-terminal顯示「Input/Output Error」

這裡了解到,可以使用journalctl -xe查看報錯,我在查看是發現下面的錯誤信息:

org.gnome.Terminal[4882]: Non UTF-8 locale (ANSI_X3.4-1968) is not supported!

從這裡看到,應該是locale設置不對然後導致的錯誤,即Gnome-Terminal只支持UTF-8的編碼。所以這裡只需要將locale設置合適即可。有下面兩種方法:

1. 修改.bashrc或.zshrc

在.bashrc或.zshrc裏面增加如下內容:

# set LC  LANG=en_US.UTF-8  LANGUAGE=  LC_CTYPE="en_US.UTF-8"  LC_NUMERIC=zh_CN.UTF-8  LC_TIME=zh_CN.UTF-8  LC_COLLATE="en_US.UTF-8"  LC_MONETARY=zh_CN.UTF-8  LC_MESSAGES="en_US.UTF-8"  LC_PAPER=zh_CN.UTF-8  LC_NAME=zh_CN.UTF-8  LC_ADDRESS=zh_CN.UTF-8  LC_TELEPHONE=zh_CN.UTF-8  LC_MEASUREMENT=zh_CN.UTF-8  LC_IDENTIFICATION=zh_CN.UTF-8  LC_ALL=    export LANG  export LANGUAGE=  export LC_CTYPE  export LC_NUMERIC  export LC_TIME  export LC_COLLATE  export LC_MONETARY  export LC_MESSAGES  export LC_PAPER  export LC_NAME  export LC_ADDRESS  export LC_TELEPHONE  export LC_MEASUREMENT  export LC_IDENTIFICATION  export LC_ALL=

然後source下,刪除之前的VNC會話,重新建立會話,查看是否正確。

2. 修改系統的locale設置

如果你是管理員的話,可以修改系統的locale設置,使得所有用戶都能正確地使用VNC。具體的代碼如下:

sudo update-locale LANG=en_US.UTF-8  sudo update-locale LANGUAGE=  sudo update-locale LC_CTYPE="en_US.UTF-8"  sudo update-locale LC_NUMERIC=zh_CN.UTF-8  sudo update-locale LC_TIME=zh_CN.UTF-8  sudo update-locale LC_COLLATE="en_US.UTF-8"  sudo update-locale LC_MONETARY=zh_CN.UTF-8  sudo update-locale LC_MESSAGES="en_US.UTF-8"  sudo update-locale LC_PAPER=zh_CN.UTF-8  sudo update-locale LC_NAME=zh_CN.UTF-8  sudo update-locale LC_ADDRESS=zh_CN.UTF-8  sudo update-locale LC_TELEPHONE=zh_CN.UTF-8  sudo update-locale LC_MEASUREMENT=zh_CN.UTF-8  sudo update-locale LC_IDENTIFICATION=zh_CN.UTF-8  sudo update-locale LC_ALL=

這樣操作後同樣需要重新建立VNC會話。

VNC連過去後,命令行字體擠在一起,看不清楚

這個原因也是因為locale設置的不對,設置了中文字體導致的問題,所以同樣地,按照上面所說的更改locale的方法,更新locale即可。

VNC中,按Tab不自動補全,而是跳轉到別的Terminal窗口

這個問題的解決方法是實驗室師兄提供的,打開~/.config/xfce4/xfce-perchaannel-xml/xfce4-keyboard-shortcuts.xml文件,將其中的

<property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>

修改為

<property name="&lt;Super&gt;Tab" type="empty"/>

然後用vncserver -kill :portid kill掉連接,再用vncserver -geometry 1920x1080 :portid來新建連接。