5

I am using a Amazon Linux 2 (a Fedora/Cent OS like distro) EC2 machine with the Deep Learning AMI (Amazon Linux 2) Version 30.1 AMI.

I want to use xclip and gedit in the remote instance. But if I type in xclip I get

Error: Can't open display: (null)

If I do gedit filename I get

(gedit:6012): Gtk-WARNING **: 00:18:40.117: cannot open display:

I have already gone through the following links:

  1. https://github.com/microsoft/WSL/issues/4933
  2. xsel: Can't open display: (null)
  3. https://askubuntu.com/questions/1035903/how-can-i-get-around-using-xclip-in-the-linux-subsystem-on-win-10
  4. https://www.cyberciti.biz/faq/error-couldnt-open-display-null-and-solution/
  5. https://superuser.com/questions/310197/how-do-i-fix-a-cannot-open-display-error-when-opening-an-x-program-after-sshi
  6. https://www.linuxquestions.org/questions/linux-software-2/xdotool-error-can%27t-open-display-null-4175527094/
  7. https://serverfault.com/questions/765606/xming-cant-open-display-error
  8. https://serverfault.com/questions/425346/cant-open-display-x11-forwarding-cent-os
  9. https://askubuntu.com/questions/305654/xclip-on-headless-server/305681#305681

And thus have,

  1. installed xauth
  2. manually set the environment variable DISPLAY to export DISPLAY="IP_of_remote_machine:0" export DISPLAY="127.0.0.1:0" export DISPLAY=:0.0 export DISPLAY=localhost:0 When I do this I get
    (gedit:6053): Gtk-WARNING **: 00:23:36.052: cannot open display: 127.0.0.1:0
    
  3. I have tried the -Y flag (-X is not an option cause of security, also -X doesn't work)
  4. I have added ForwardX11 yes in the client side's ~/.ssh/config and X11Forwarding yes in the server side's /etc/ssh/sshd_config

Nothing works. Any directions?

EDIT:

I also watched this video which says that DISPLAY should not be hardcoded. But my DISPLAY is not set automatically. When I do a echo $DISPLAY I get nothing.

So I did a xauth list which gave me

ip-x-y-x.ec2.internal/unix:10  MIT-MAGIC-COOKIE-1  c84bcd904dd50f7776f667eca7a480f5

so I did

export DISPLAY=localhost:10.0

Still I get the same error.

2
  • When you use ssh -Y user@remote are you in some kind of terminal? What happens if you say echo $DISPLAY in that terminal before you use ssh? You shouldn't need to set DISPLAY manually, that is what the -Y should be doing automatically.
    – icarus
    Jul 17 '20 at 1:25
  • Try running ssh with the "-vv" option to print debugging info. Then edit your question to include the exact ssh command that you ran, the debugging output, and any relevant entries from your .ssh/config file.
    – Kenster
    Jul 17 '20 at 1:55
4

I solved this problem by simply hardcoding $DISPLAY as :1,

export DISPLAY=:1

in my .bashrc file.

I however, still don't understand why this works. Here is the output of xauth list

ip-172-31-74-230.ec2.internal:1  MIT-MAGIC-COOKIE-1  8a44b41e42cae52c6acd4747763bb985
ip-172-31-74-230.ec2.internal/unix:1  MIT-MAGIC-COOKIE-1  8a44b41e42cae52c6acd4747763bb985
ip-172-31-74-230.ec2.internal:2  MIT-MAGIC-COOKIE-1  e24f36d585762b0c0fe24010b99e448d
ip-172-31-74-230.ec2.internal/unix:2  MIT-MAGIC-COOKIE-1  e24f36d585762b0c0fe24010b99e448d
ip-172-31-74-230.ec2.internal/unix:10  MIT-MAGIC-COOKIE-1  c84bcd904dd50f7776f667eca7a480f5
1

As you know the DISPLAY environment variable is exported to any x-Client program that needs the specification for the x-server on your original machine (the PC you typed in the ssh command on).

The way I do this these days, is to be lazy and ask the environment:

 $ env | grep SSH
SSH_CLIENT=192.168.182.159 45462 22
SSH_TTY=/dev/pts/28
SSH_CONNECTION=192.168.182.159 45462 192.168.188.120 22

SSH_CLIENT and SSH_CONNECTION show you the IP address of your origin terminal. In which case I export the rollowing:

 $ export DISPLAY="192.168.182.159:0.0"
 $ xeyes

Start-up xeyes to satisfy yourself that everything is working for you. Your display is ready to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.