Error: Cannot open display: (null) when using Xclip to copy ssh public key

Next in Creating SSH Keys , It Says

sudo apt-get install xclip

# Download and install xclip. If you do not have apt-get , you may need to use another installer (e.g. yum )

xclip -sel clip <~ / .ssh / id_rsa.pub

# Copy the contents of the id_rsa.pub file to the clipboard

But after running xclip -sel clip < ~/.ssh/id_rsa.pub I get Error: Can't open display: (null) What is the problem? I googled around but found nothing about it

+75
linux ssh
09 Sep '13 at 10:10
source share
8 answers

DISPLAY=:0 xclip -sel clip < ~/.ssh/id_rsa.pub does not work for me ( ubuntu 14.04 ), but you can use:

 cat ~/.ssh/id_rsa.pub 

get your public key

+84
Jun 02 '14 at 15:56
source share

Depending on the date of this question, the original poster would not use the Windows subsystem for Linux . But if you, and get the same error, the following alternative works:

 clip.exe < ~/.ssh/id_rsa.pub 

Thanks to this page, to indicate that Windows' clip.exe (and you must enter ".exe"), you can run it from the bash shell.

+30
Jul 04 '17 at 20:53 on
source share

This was too good an answer to not post it here. This is from Gilles , the same user from Askubuntu:

The clipboard is provided by the X server . It does not matter whether the server is standalone or not, it is important that your local graphical session is available for programs running on a remote computer. Thanks to the transparent design for the X network, this is possible.

I assume that you are connecting to a remote server with SSH from a Linux machine. Ensure that X11 forwarding is enabled both in the client configuration and in the server configuration. In the client configuration, you need to have the ForwardX11 yes line in ~/.ssh/config so that ForwardX11 yes its default, or pass the -X option to the ssh command for this session only. In the server configuration, you need to have the line X11Forwarding yes in /etc/ssh/sshd_config (it is present by default in Ubuntu).

To check if X11 forwarding is enabled, look at the value of the DISPLAY environment variable: echo $DISPLAY . You should see a value like localhost:10 (applications running on a remote computer are told that they should connect to a display running on the same computer, but this display connection is actually sent via SSH to the client-side display). Please note that if DISPLAY not installed, it does not need to be configured manually: the environment variable is always set correctly if the redirection is set. If you need to diagnose problems with the SSH connection, pass the -vvv ssh option to get detailed information about what is happening.

If you connect using other means, you may or may not be able to achieve X11 redirection. If your client is running Windows, PuTTY supports X11 forwarding; You will have to start the X server on a Windows computer, such as Xming .

Gilles from Askubuntu

+22
Sep 18 '16 at 10:13
source share

If you are trying to use xclip on a remote host, just add -X to your ssh command

 ssh user@host -X 

More information can be found here: https://askubuntu.com/a/305681

+14
Apr 13 '15 at 8:35
source share

Read the documentation you linked. This is totally stupid! xclip is just a clipboard. You will find other ways to copy the key paste ... (I'm sure)




If you are not working from within the graphical X session, you need to pass the $DISPLAY var var command to the command. Run it as follows:

 DISPLAY=:0 xclip -sel clip < ~/.ssh/id_rsa.pub 

Of course :0 depends on the display you are using. If you have a typical desktop computer, it is likely that it :0

+8
Sep 09 '13 at 10:15
source share

Try it and it will work like a charm. I had the same error, but this approach did the trick for me:

 ssh USER@REMOTE "cat file"|xclip -i 
+8
Jun 18 '15 at 18:01
source share

The following also works for me:

 ssh <user>@<host> "cat <filepath>"|pbcopy 
+6
Feb 15 '16 at 9:45
source share

add the root user of this command: ssh user_to_acces @hostName -X

user_to_acces = user hostName = hostname of the machine

+1
Feb 12 '19 at 11:16
source share



All Articles