溫馨提示×

Ubuntu Minimal如何遠程桌面連接

小樊
54
2025-09-21 02:01:56
欄目: 智能運維

Prerequisites for Remote Desktop on Ubuntu Minimal
Ubuntu Minimal is a headless (GUI-less) system, so you must first install a desktop environment and a remote desktop service. Common choices include:

  • Desktop Environments: XFCE (lightweight, recommended for servers), GNOME (default but resource-heavy).
  • Remote Desktop Services: XRDP (supports RDP protocol, works with Windows/macOS/Linux clients), VNC (e.g., TigerVNC, x11vnc, supports cross-platform graphical access).

Method 1: Using XRDP (Recommended for Most Users)
XRDP is the most widely used solution for remote desktop access on Ubuntu, as it uses the standard RDP protocol (compatible with Windows Remote Desktop Client).

1. Install a Desktop Environment

First, update your system and install a lightweight desktop (e.g., XFCE) to ensure smooth performance:

sudo apt update && sudo apt upgrade -y
sudo apt install xfce4 -y  # XFCE is lightweight; use 'ubuntu-desktop' for full GNOME if resources allow
2. Install XRDP

Install the XRDP server package:

sudo apt install xrdp -y
3. Configure XRDP to Use Your Desktop Environment

XRDP needs to know which desktop environment to launch. For XFCE, create a .xsession file in your home directory:

echo xfce4-session > ~/.xsession

This tells XRDP to start XFCE when a user logs in remotely.

4. Start and Enable XRDP

Enable XRDP to start on boot and launch it immediately:

sudo systemctl enable xrdp
sudo systemctl start xrdp
5. Configure Firewall (If UFW is Enabled)

Allow RDP traffic (port 3389) through the firewall:

sudo ufw allow 3389/tcp
6. Connect from a Client
  • Windows: Open the Remote Desktop Connection app (press Win + R, type mstsc), enter your Ubuntu server’s IP address, and click Connect. Log in with your Ubuntu username and password.
  • Linux/macOS: Use a client like Remmina (install via sudo apt install remmina on Linux) or Microsoft Remote Desktop. Enter the IP address and credentials to connect.

Method 2: Using VNC (Alternative for Graphical Access)
VNC provides cross-platform graphical access but is less secure than XRDP (use SSH tunneling for encryption).

1. Install a Desktop Environment

As with XRDP, install a lightweight desktop (e.g., XFCE):

sudo apt install xfce4 -y
2. Install a VNC Server

Install TigerVNC (a stable, high-performance VNC server):

sudo apt install tigervnc-standalone-server -y
3. Set a VNC Password

Set a password for VNC access (this will be required when connecting):

vncpasswd

Enter and confirm your password (max 8 characters).

4. Configure the VNC Server

Create a systemd service file to autostart VNC:

mkdir -p ~/.config/systemd/user
cat <<EOF > ~/.config/systemd/user/x11vnc.service
[Unit]
Description=Start x11vnc at startup.
After=graphical.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -display :0 -auth /home/your_username/.Xauthority -forever -loop -noxdamage -repeat -rfbauth /home/your_username/.vnc/passwd -rfbport 5900 -shared
Restart=on-failure

[Install]
WantedBy=default.target
EOF

Replace your_username with your actual username.

5. Enable and Start the VNC Service

Enable the service to start on login and start it now:

systemctl --user enable x11vnc.service
systemctl --user start x11vnc.service
6. Configure Firewall (If UFW is Enabled)

Allow VNC traffic (port 5900):

sudo ufw allow 5900/tcp
7. Connect from a Client
  • Windows: Use VNC Viewer (download from RealVNC’s website), enter your Ubuntu server’s IP address (e.g., 192.168.1.100:5900), and log in with your VNC password.
  • Linux/macOS: Use the vncviewer command (install via sudo apt install xtightvncviewer on Linux):
    vncviewer your_server_ip:5900
    

Troubleshooting Common Issues

  • Black Screen in XRDP: Ensure your .xsession file is correctly set (e.g., xfce4-session for XFCE) and restart XRDP:
    sudo systemctl restart xrdp
    
  • VNC Connection Refused: Verify the VNC service is running (systemctl --user status x11vnc.service) and the port (5900) is open in the firewall.
  • Slow Performance: Use a lightweight desktop (XFCE) and enable compression in your VNC/RDP client settings.

By following these steps, you can successfully set up remote desktop access on Ubuntu Minimal using either XRDP (recommended) or VNC. Choose the method that best fits your security and compatibility needs.

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女