Home > System Tutorial > Linux > body text

Ubuntu16.04 uses VNC to connect to the GNOME desktop

WBOY
Release: 2024-06-01 15:37:17
Original
722 people have browsed it

Ubuntu16.04 用VNC链接 GNOME 桌面

0x01 Before you begin

Since in some cases, it is necessary to use the graphical interface of remote desktop to connect to the server, so here is a brief introduction on how to install VNC and desktop environment under Ubuntu 16.04 LTS.
Be sure to confirm that your server has 2GB of memory or above to better use the graphical interface, otherwise it will be stuck or even crash.

0x02 Install desktop environment

If you do not install a desktop environment, you will see a gray screen and nothing can be seen after VNC connection.

1. Log in to the server using SSH

Must use root account.

2. Update source and system

Enter the following command:

apt update
apt upgrade -y
Copy after login
3. Install desktop environment

Here we introduce how to install and use the unity desktop, and use gnome 2 for remote connection.

Full installation (not recommended):

apt install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal -y
Copy after login

Install core components only:
If you do not install additional components such as office, browser, etc., you can use the following command:

apt-get install --no-install-recommends ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal -y
Copy after login
0x03 Install VNC server

1. Enter the following command:

apt install vnc4server -y
Copy after login

2. Test connection:

Note: The user name fills in the user name currently in use, such as root. IP Address Fill in the IP address of the current server.

ssh -L 5901:127.0.0.1:5901 用户名@IP地址或网址
Copy after login

When prompted whether to continue the connection, enter yes. After entering the password, you can log in successfully, which proves that the configuration is correct. Otherwise, you need to check whether the firewall has port 5901 open.

0x04 Configure VNC server
1. Enter the following command:
vncserver :1
Copy after login

The first startup will require you to enter the VNC password twice and the password will not be visible. If you need to change the VNC connection password later, you only need to enter vncpassword.

2. End vncserver

Enter the following command:

vncserver -kill :1
Copy after login
3. Modify the configuration file

1. 修改 ~/.vnc/xstartup,在 x-window-manager & 的后面新增下面这 4 行:

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
Copy after login

完整配置文件如下:

 	#!/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 &
Copy after login

2. 启动 vncserver:

vncserver :1
Copy after login

3. 配置开机启动:

首先输入 crontab 命令。

会提示选择默认的编辑器。推荐使用 vim,选择 vim.basic 就可以了。

Select an editor. To change later, run ‘select-editor’.
1. /bin/ed
2. /bin/nano <---- easiest 3. /usr/bin/vim.basic 4. /usr/bin/vim.tiny Choose 1-4 [2]: 在末尾另起一行输入如下命令:

@reboot /usr/bin/vncserver :1
Copy after login

提示:
切换英文输入法,按 i 改为插入模式,粘贴完毕后,按 Esc 退出插入模式,然后按 shift 和 : 键,出现“:”后,输入 wq 保存,回车退出。

重启服务器。

reboot
Copy after login
0x05 本地环境安装 VNC 客户端

在 Windows 下,建议使用 TigerVNC,小巧好用。
官方下载地址:http://tigervnc.bphinz.com/nightly/

首次连接会报个错误,直接输入如下命令新建目录即可:

mkdir -p /root/.config/nautilus
Copy after login
0x06 注意事项

在这里要告诉大家的是,Gnome 3 和 Unity 桌面,由于兼容性问题,连上后会什么也无法显示。所以在这里远程桌面连接只能使用 gnome 2。

The above is the detailed content of Ubuntu16.04 uses VNC to connect to the GNOME desktop. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!