温馨提示×

ubuntu tigervnc与xrdp如何配合

小樊
54
2025-10-31 23:40:02
栏目: 智能运维

Integrating TigerVNC with xrdp on Ubuntu for Remote Desktop Access
TigerVNC and xrdp are often used together to enable remote desktop access to Ubuntu systems. TigerVNC serves as the VNC server, handling graphical display and input, while xrdp acts as an RDP (Remote Desktop Protocol) gateway, allowing Windows and other RDP clients to connect to the Ubuntu desktop. Below is a step-by-step guide to configuring them for seamless integration.

1. Install Required Packages

First, install TigerVNC Server and xrdp on your Ubuntu system. Open a terminal and run:

sudo apt update
sudo apt install tigervnc-standalone-server tigervnc-common xrdp -y

This installs TigerVNC (for VNC functionality) and xrdp (for RDP compatibility).

2. Configure TigerVNC for Desktop Environment

TigerVNC requires a startup script (~/.vnc/xstartup) to launch the desktop environment. Without proper configuration, remote connections may fail or display a blank screen.

  • Create/Edit the xstartup File:
    Run the following command to open the file in a text editor:
    nano ~/.vnc/xstartup
    
  • Add Desktop Environment Launch Commands:
    For GNOME (Ubuntu’s default desktop), add these lines:
    #!/bin/sh
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    export XKL_XMODMAP_DISABLE=1
    xrdb $HOME/.Xresources
    gnome-session &
    
    For XFCE (a lightweight alternative), use:
    #!/bin/sh
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    startxfce4 &
    
  • Make the Script Executable:
    Save the file and run:
    chmod +x ~/.vnc/xstartup
    
    This ensures the script runs when TigerVNC starts.

3. Configure xrdp to Use TigerVNC

xrdp needs to know which VNC server to use for remote sessions. By default, xrdp uses its own session manager, but we’ll point it to TigerVNC.

  • Edit the xrdp Start Script:
    Open the xrdp startup file:
    sudo nano /etc/xrdp/startwm.sh
    
  • Modify the End of the File:
    Comment out any existing exec lines (e.g., exec /etc/X11/xinit/xinitrc) and add:
    unset DBUS_SESSION_BUS_ADDRESS
    unset XDG_RUNTIME_DIR
    /usr/bin/vncserver :1
    
    This tells xrdp to start TigerVNC (listening on display :1, which corresponds to port 5901) when a user connects.

4. Set a VNC Password

TigerVNC requires a password for remote access. Run:

vncpasswd

Enter and confirm a password (note: this is separate from your Ubuntu login password). The password must be between 6–8 characters long.

5. Configure Firewall for Remote Access

If you’re using UFW (Ubuntu’s default firewall), allow traffic on the RDP port (3389) and TigerVNC ports (5901+). Run:

sudo ufw allow 3389/tcp  # RDP port for xrdp
sudo ufw allow 5901/tcp  # TigerVNC port (display :1)
sudo ufw enable          # Enable firewall if not already active

6. Restart Services for Changes to Take Effect

Restart both xrdp and TigerVNC to apply configurations:

sudo systemctl restart xrdp
vncserver -kill :1  # Stop any running TigerVNC instances
vncserver :1        # Restart TigerVNC

7. Connect to Ubuntu via RDP

On a Windows machine, open the Remote Desktop Connection client (built into Windows). Enter the Ubuntu system’s IP address (e.g., 192.168.1.100) and click Connect. When prompted, enter your Ubuntu username and the VNC password you set earlier. You should now see the Ubuntu desktop.

Troubleshooting Common Issues

  • Black Screen After Connection:
    Ensure the ~/.vnc/xstartup file is executable and contains the correct desktop launch commands. Restart xrdp and TigerVNC after making changes.
  • xrdp Fails to Start:
    Check the xrdp logs (/var/log/xrdp.log and /var/log/xrdp-sesman.log) for errors. Common fixes include ensuring xrdp and tigervnc-standalone-server are installed and the startwm.sh script is correctly configured.
  • Firewall Blocking Connections:
    Verify that UFW allows ports 3389 (RDP) and 5901 (TigerVNC). Use sudo ufw status to check rules.

By following these steps, you can integrate TigerVNC with xrdp on Ubuntu to enable secure, cross-platform remote desktop access. This setup leverages TigerVNC’s performance and xrdp’s compatibility with RDP clients, providing a flexible solution for remote administration or user access.

0