Install Xfce and VNC on Ubuntu 18.04.2
sudo apt update && sudo apt upgrade –y1.Install Xfce and VNC
sudo apt install xfce4 xfce4-goodies tightvncserver
2.Configure VNC Server
vncserver输入一个至少8个字符的密码。不需要view-only 密码。现在需要新建/home/myroot/.vnc/xstartup 文件,在此之前,先kill VNC servicevncserver -kill :1cp ~/.vnc/xstartup ~/.vnc/xstartup.bakvi ~/.vnc/xstartup在文件后增加:startxfce4 &sudo chmod +x ~/.vnc/xstartup重新运行vncserver $ vncserver
3. 建立 SSH Tunnel
为了在vnc server和vnc client 之间建立安全加密的通信,可以通过 PuTTY client 建立 SSH Tunnel 将 vncserver 的远程Port 5901与本机的端口5901绑定。
打开 PuTTY ,
选择 Connection > SSH > Tunnels.
在 Source Port, 输入 5901
In Destination, 输入: ip:5901
点击 Add.
https://s1.运维网.com/images/blog/201903/03/dba9b4735946fd4e2c5701bdd531db7b.png
选择 Session.在 Host Name(or IP address),输入用户名@IP, (e.g, myroot@172.16.11.80).
在 Saved Sessions, 输入“SSH Tunnel for VNC”
点击 Save 保存,然后点 Open .
https://s1.运维网.com/images/blog/201903/03/5ada2389b4b72658075b5560c44ccdc1.png
https://s1.运维网.com/images/blog/201903/03/032ee34847358f33381e89ddf6504ad7.png
输入密码(是登录Ubuntu的密码,不是VNCServer的密码),登录Ubuntu。
查看日志确认SSH Tunnel 是否建立成功:
点击 PuTTY 图标, 选择Event Log
https://s1.运维网.com/images/blog/201903/03/e3a99fce84a39b43195ed401d3993d53.png
现在可以通过VNC Client 去连接 VNC Server: 输入 localhost:5901
然后点”Connect“
https://s1.运维网.com/images/blog/201903/03/a0aa106470182d4988f3dce9d95aba14.png
输入VNC Server 连接密码:
https://s1.运维网.com/images/blog/201903/03/9fe0ca6f60efacde2f5eaee31d8f1e93.png
连接成功:点”Use default config“
https://s1.运维网.com/images/blog/201903/03/9e25e200b30645241b647c7f1b4d71fc.png
https://s1.运维网.com/images/blog/201903/03/0d461f75d1843b5ea1566a6506ca0b42.png
4. 配置 VNC Server 作为服务运行
为了让VNC 在服务器重启时自动运行,可以使VNC server 作为服务运行。
$ sudo vi /etc/systemd/system/vncserver@.service
Description=Start TightVNC server at startup
After=syslog.target network.target
Type=forking
User=
Group=
WorkingDirectory=/home/
PIDFile=/home//.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry:%i
ExecStop=/usr/bin/vncserver -kill :%i
WantedBy=multi-user.target
https://s1.运维网.com/images/blog/201903/03/790be440d385e7feeeabebc3347aa578.png
重载 daemon-reload:
Reload systemd manager configuration.
sudo systemctl daemon-reload
Enable the unit file you just created.
sudo systemctl enable vncserver@1.service
Kill vncserver.
vncserver -kill :1
Start vncserver again.
sudo systemctl start vncserver@1
Ensure service is running.
sudo systemctl status vncserver@1
https://s1.运维网.com/images/blog/201903/03/58f505567fd90106a497673a8b6f9247.png
这样每次重启后,要连接vnc server,先通过PuTTy 建立SSH Tunnel 再通过vnc client 连接。
sudo apt install firefox
安装firefox:
https://s1.运维网.com/images/blog/201903/03/9512b27e21aacc406d43b906ed41cc45.png
https://s1.运维网.com/images/blog/201903/03/926f9eff88bead98f0d834cfc958c09a.png
页:
[1]