Skip to content

X Window forwarding

Kiriti Gowda edited this page Jan 14, 2021 · 5 revisions

Securely run graphical applications remotely

The X Window System (also known as X11, or just X) is a software package and network protocol that lets you interact locally, using your personal computer's display, mouse, and keyboard, with the graphical user interface (GUI) of an application running on a remote networked computer.

You can use X forwarding in an SSH session on your personal computer to securely run graphical applications (X clients) installed on remote systems

Requirements

For X forwarding in SSH to work, your personal computer must be running an X server program. The X server program manages the interaction between the remote application (the X client) and your computer's hardware.

Linux

Most Linux distributions have the X server installed, but if your personal computer is running Windows or macOS, you will most likely need to install and run an X server application. If OpenSSH not installed on your system, use below command to install

sudo apt install openssh-server

Windows

  • Download and install Xming.
    • For X forwarding to work, you'll need to start Xming before connecting to the remote system with your SSH client
    • Use PuTTY terminal
    • In PuTTY, you can enable X forwarding in new or saved SSH sessions by selecting Enable X11 forwarding in the PuTTY Configuration window (Connection > SSH > X11).

macOS

  • Download and install XQuartz
    • For X forwarding to work, you'll need to start XQuartz before making an SSH connection to the remote system
    • Once XQuartz launches, you can use X forwarding with SSH from the Terminal or from the xterm application in XQuartz
    • You may need to edit your ssh_config file, found at /etc/ssh/ssh_config or ~/.ssh/config
    • If ssh_config includes #X11Forwarding no / X11Forwarding no, remove the leading #, and/or change to X11Forwarding yes

NOTE: The remote computer's SSH application must be configured to accept X server connections.

Use SSH with X forwarding

Linux or macOS

  • Use SSH with X forwarding on your Linux or macOS personal computer to run an X client application installed on a remote system
ssh -X {USER_NAME}@{REMOTE_SERVER_ADDRESS} -p {22/PORT_NUMBER}
  • Verify connection using xclock
    • If X forwarding is working, the xclock graphical clock will appear on your personal computer's desktop
xclock

PuTTY for Windows

  • To use SSH with X forwarding in PuTTY for Windows:

    • Launch your X server application (for example, Xming)
  • Make sure your connection settings for the remote system have Enable X11 forwarding selected; in the "PuTTY Configuration" window

    • see Connection > SSH > X11
  • Verify connection using xclock

    • If X forwarding is working, the xclock graphical clock will appear on your personal computer's desktop
xclock

X Window Forwarding with Dockers

Steps to Launch Port Forwarding

  • Step 1 - Launch Docker on a remote server - ssh-port-forward-enabled in the Terminal 1
sudo docker run -it --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --device=/dev/mem --group-add video --network host --env DISPLAY=unix$DISPLAY --privileged --volume $XAUTH:/root/.Xauthority --volume /tmp/.X11-unix/:/tmp/.X11-unix kiritigowda/ubuntu-18.04:ssh-port-forward-enabled
  • Step 2 - Start ssh service in Terminal 1 within the launched Docker
sudo service ssh start
  • Step 3 - Connect to the remote server with Terminal 2 with -X option

  • Step 4 - Login to the Docker launched on the remote server on Terminal 2

ssh -X root@localhost -p 23

NOTE: password - root

  • Step 5 - Test X-11 port forwarding
export PATH=$PATH:/opt/rocm/mivisionx/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/mivisionx/lib
runvx /opt/rocm/mivisionx/samples/gdf/canny.gdf
  • Step 6 - Check for ROCm version
dpkg -l | grep rocm