Yan
Yan Just a simple man.

Ubuntu下使用VNC

Ubuntu下使用VNC

这篇记录如何在Ubuntu20.04下配置使用VNC。

安装

  1. 安装依赖
1
$ sudo apt-get install gnome-session-flashback
  1. 安装VNC Server
1
$ sudo apt-get install tigervnc-standalone-server

配置

  1. 关闭防火墙
1
2
$ sudo ufw disable
Firewall stopped and disabled on system startup

关闭以后可以通过status命令查看

1
2
$ sudo ufw status
Status: inactive
  1. 设置密码
1
2
3
4
$ vncpasswd 
Password:
Verify:
Would you like to enter a view-only password (y/n)? n

这个密码是远程连接时需要输入的密码

  1. 设置配置文件
1
$ vim ~/.vnc/xstartup

配置内容如下

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/sh

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:GNOME"
export XDG_MENU_PREFIX="gnome-flashback-"
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check &
  1. 添加执行权限
1
$ sudo chmod +x  ~/.vnc/xstartup

使用

  1. 启动服务端
1
2
3
4
5
6
7
8
9
$ vncserver -localhost no
Cleaning stale pidfile '/home/khadas/.vnc/localhost:1.pid'!

New 'localhost:1 (khadas)' desktop at :1 on machine localhost

Starting applications specified in /home/khadas/.vnc/xstartup
Log file is /home/khadas/.vnc/localhost:1.log

Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/khadas/.vnc/passwd :1 to connect to the VNC server.
  1. 查看端口

根据第一步提供的信息/home/khadas/.vnc/localhost:1.log

1
2
3
4
5
6
7
$ cat /home/khadas/.vnc/localhost:1.log
Mon Jul 12 07:39:39 2021
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on local interface(s), port 5901
 vncext:      created VNC server for screen 0
 ComparingUpdateTracker: 0 pixels in / 0 pixels out
 ComparingUpdateTracker: (1:nan ratio)
  1. 客户端连接

vnc view下载地址,选择自己对应的平台

客户端连接格式

1
ip:part #示例192.168.1.172:5091

输入密码即可控制远程桌面