Ubuntu 图形化设置
图形化
-
更新
sudo apt update && sudo apt full-upgrade -y
-
安装xfce
sudo apt install -y xfce4 xfce4-goodies dbus-x11 x11-xserver-utils xterm fonts-noto-cjk xkb-data
远程连接
-
安装tigervnc
sudo apt install -y tigervnc-standalone-server
-
设置密码
切换到普通用户后
vncpasswd
-
测试连接
开放5901端口后
vncserver -geometry 1280x720 -localhost yes :1
Win+R
输入 powershell 后回车打开本地终端后执行ssh -L 5901:localhost:5901 用户名@服务器IP地址
下载vnc viewer客户端:点击前往,安装后使用
localhost:5901
连接测试测试完成后关闭连接
vncserver -kill :1
-
启动脚本
cat > ~/.vnc/xstartup <<'EOF' #!/bin/sh unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS # 可选:加载 X 资源 if [ -r $HOME/.Xresources ]; then xrdb $HOME/.Xresources fi # 启动 Xfce,如失败则退回到 xterm 便于调试 command -v startxfce4 >/dev/null 2>&1 && exec dbus-launch --exit-with-session startxfce4 exec xterm EOF chmod +x ~/.vnc/xstartup
-
开机自启
- 服务端
sudo tee /etc/systemd/system/vnc@.service >/dev/null <<'EOF' [Unit] Description=TigerVNC server for %i After=network.target [Service] Type=forking User=%i WorkingDirectory=/home/%i # 分离 PIDFile,确保路径一定存在 PIDFile=/home/%i/.vnc/%H:1.pid # 尝试先杀旧会话(忽略错误) ExecStartPre=/usr/bin/env bash -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || true' # 仅绑定本地环回;如需公网开放,把 -localhost yes 改 no ExecStart=/usr/bin/vncserver \ -geometry 1280x720 \ -localhost yes \ :1 ExecStop=/usr/bin/vncserver -kill :1 # 让 systemd 在崩溃后自动重启,不超过 3 次 Restart=on-failure RestartSec=5 StartLimitBurst=3 StartLimitIntervalSec=60 [Install] WantedBy=multi-user.target EOF sudo systemctl daemon-reload sudo systemctl enable --now vnc@用户名.service
-
客户端
Win+R
输入 shell:startup 后回车在打开的目录里右键新建快捷方式,目标为cmd /k "ssh -L 5901:localhost:5901 用户名@IP地址 -p SSH端口"
浏览器
firefox
-
创建目录
sudo install -d -m 0755 /etc/apt/keyrings
-
导入密钥
wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null
如果没有安装 wget,请通过命令
sudo apt-get install wget
安装。 -
核对密钥
指纹应该是 35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3
可以用以下命令检查
gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}'
-
添加到源列表
echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | sudo tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null
-
配置源优先级
echo ' Package: * Pin: origin packages.mozilla.org Pin-Priority: 1000 ' | sudo tee /etc/apt/preferences.d/mozilla
-
更新并安装
sudo apt-get update && sudo apt-get install firefox
falkon
-
安装驱动
sudo apt install -y libqt5sql5-sqlite
-
安装falkon
sudo apt install -y falkon
-
创建快捷方式
cat <<'EOF' | sudo tee /usr/share/applications/falkon-lowram.desktop [Desktop Entry] Name=Falkon (Low-RAM) Exec=falkon --enable-low-end-device-mode --process-per-site \ --disable-gpu --disable-webgl Icon=falkon Type=Application Categories=Network;WebBrowser; EOF
防火墙
-
开放 VNC 端口: 假设你使用的是显示编号 :1(即端口 5901),可以使用以下命令开启端口
Copysudo ufw allow 5901/tcp
如果你打算使用其他显示编号,记得相应调整端口号
-
开放 HTTP 端口(如需要): 如果需要通过 HTTP 访问 VNC 会话(比如用浏览器),则需要开启对应的 HTTP 端口:
Copysudo ufw allow 5801/tcp
-
查看防火墙状态: 使用以下命令确认端口是否已正确开启
Copysudo ufw status
删除配置
-
终止
sudo systemctl stop vnc@1.service # 如曾经启用 sudo systemctl disable vnc@1.service # 防止开机自启 sudo vncserver -kill :1 2>/dev/null || true sudo pkill -u ${whoami} Xtigervnc || true # 冗余保险
-
清空历史
sudo truncate -s 0 ~/.bash_history
-
清空设置
sudo mkdir -p ~/backup_cleanup sudo mv ~/.vnc \ ~/.cache \ ~/.config \ ~/.dbus \ ~/.local \ ~/.xsession-errors \ ~/.Xauthority \ ~/.ICEauthority \ ~/backup_pre_cleanup_$(date +%F)/ 2>/dev/null || true # 彻底删除 sudo rm -rf ~/backup_cleanup