在云服务器上如何为Ubuntu安装图形桌面?

在云服务器上为Ubuntu安装图形桌面,可以通过以下步骤完成。这里以Ubuntu 20.04/22.04为例,提供两种常用方案:


方案一:安装轻量级桌面(推荐,资源占用低)

适合云服务器,资源消耗较小。

1. 更新系统

sudo apt update
sudo apt upgrade -y

2. 安装桌面环境

  • Ubuntu Desktop(完整版,较重)
    sudo apt install ubuntu-desktop -y
  • Xfce(轻量级推荐)
    sudo apt install xfce4 xfce4-goodies -y
  • GNOME(默认桌面)
    sudo apt install gnome-session gdm3 -y

3. 安装远程桌面服务(通过VNC或RDP访问)

选项A:使用VNC(以TightVNC为例)
sudo apt install tightvncserver -y
# 首次启动设置密码
vncserver
# 后续启动可用
vncserver :1 -geometry 1280x720 -depth 24
选项B:使用xRDP(通过Windows远程桌面连接)
sudo apt install xrdp -y
sudo systemctl enable xrdp
sudo systemctl start xrdp

4. 配置防火墙(如果启用)

# 开放VNC端口(默认5901)
sudo ufw allow 5901
# 开放RDP端口(默认3389)
sudo ufw allow 3389

5. 重启服务

sudo systemctl restart xrdp  # 如果使用xRDP

方案二:使用浏览器访问的桌面(无需VNC/RDP)

通过浏览器直接访问桌面,适合临时使用。

安装Guacamole(Web远程桌面)

# 安装Docker
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker

# 运行Guacamole容器
sudo docker run -d --name guacamole -p 8080:8080 guacamole/guacamole

访问 http://服务器IP:8080,默认登录账号 guacadmin/guacadmin


连接方式

  1. VNC连接
    • 本地安装VNC Viewer,输入 服务器IP:1 和设置的密码。
  2. Windows远程桌面
    • 直接使用“远程桌面连接”,输入服务器IP。
  3. 通过SSH隧道(安全推荐)
    ssh -L 5901:localhost:5901 用户名@服务器IP

    然后VNC连接 localhost:5901


注意事项

  1. 云安全组:确保在云控制台开放对应端口(3389、5901、8080等)。
  2. 资源消耗:图形桌面会占用内存/CPU,轻量级桌面(Xfce)建议服务器至少1GB内存。
  3. 自启动:设置VNC服务自启动:
    sudo nano /etc/systemd/system/vncserver.service

    添加配置后执行:

    sudo systemctl enable vncserver

卸载图形桌面(如需恢复无桌面)

# 卸载桌面包(以Xfce为例)
sudo apt remove xfce4 xfce4-goodies -y
sudo apt autoremove -y
# 卸载xRDP
sudo apt remove xrdp -y

根据需求选择方案,轻量级桌面更适合云服务器环境。

云服务器