Skip to content

Instantly share code, notes, and snippets.

@jay-johnson
Last active January 20, 2024 02:37
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jay-johnson/9184a4e9df277dd2d518eaa4343ece53 to your computer and use it in GitHub Desktop.
Save jay-johnson/9184a4e9df277dd2d518eaa4343ece53 to your computer and use it in GitHub Desktop.
Setting up X11 for use on an EC2 host

Run this on EC2 host

  1. Set these attributes in /etc/ssh/sshd_config
# cat /etc/ssh/sshd_config  | grep X11
X11Forwarding yes 
X11DisplayOffset 10
X11UseLocalhost yes 
  1. service ssh restart
  2. xhost +root
  3. export DISPLAY=localhost:10.0
  4. cp /home/ubuntu/.Xauthority /root/
  5. xauth list
# xauth list
<Internal Host Name>/unix:10  MIT-MAGIC-COOKIE-1  A_STRING_OF_CHARACTERS
# 
  1. Logout

Add the EC2 X11 Session to your localhost's Xauthority

$ xauth
Using authority file /home/driver/.Xauthority
xauth> add <Internal Host Name>/unix:10  MIT-MAGIC-COOKIE-1  <A STRING OF CHARACTERS>
xauth> exit
Writing authority file /home/driver/.Xauthority
$

Log back into the EC2 host with -X

  1. Here's the example I am using

    $ ssh -X -i ~/.ssh/<pem file> -o StrictHostKeyChecking=no ubuntu@<EC2 HOST PUBLIC DNS NAME>
    
  2. Try an application that uses an X11 session

./qt-opensource-linux-x64-5.3.2.run

Troubleshooting

X11 Wrong Authentication Errors

After you log out and log back into EC2 you get X11 errors like this:

$ sudo su
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
  1. Copy over the working version from the ec2-user or ubuntu:
# cp /home/ubuntu/.Xauthority /root/
  1. Find the new X11 session
# xauth list
<Internal Host Name>/unix:10  MIT-MAGIC-COOKIE-1  <A STRING OF CHARACTERS>
  1. From your localhost add it to the X11 Authority
$ xauth
Using authority file /home/driver/.Xauthority
xauth> add <Internal Host Name>/unix:10  MIT-MAGIC-COOKIE-1  <A STRING OF CHARACTERS>
xauth> exit
Writing authority file /home/driver/.Xauthority
$ 
  1. Try an application that uses X11
# xclock
@guanhuaw
Copy link

A little reminder for new Mac users like me: remember to install XQuartz, otherwise on the EC2 instance $DISPLAY will be void.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment