Error: Can't open display: (null) when using Xclip to copy ssh public key
我关注"生成SSH密钥",它说
sudo apt-get install xclip
# Downloads and installs xclip. If you don't have
apt-get , you might need to use another installer (likeyum )xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
但是运行
问题是什么? 我四处搜寻,但一无所获
1 | cat ~/.ssh/id_rsa.pub |
获取您的公钥
基于此问题的日期,原始发布者将不会使用Windows Subsystem for Linux。但是,如果您遇到相同的错误,则可以使用以下替代方法:
1 | clip.exe < ~/.ssh/id_rsa.pub |
感谢此页面指出Windows的clip.exe(并且您必须键入" .exe")可以从bash shell运行。
这是一个很好的答案,不能在此处发布。来自askubuntu的一位用户Gilles:
The clipboard is provided by the X
server. It doesn't matter
whether the server is headless or not, what matters is that your local
graphical session is available to programs running on the remote
machine. Thanks to X's network-transparent design, this is possible.I assume that you're connecting to the remote server with SSH from a
machine running Linux. Make sure that X11 forwarding is enabled both
in the client configuration and in the server configuration. In the
client configuration, you need to have the lineForwardX11 yes in
~/.ssh/config to have it on by default, or pass the option-X to
thessh command just for that session. In the server configuration,
you need to have the lineX11Forwarding yes in
/etc/ssh/sshd_config (it is present by default on Ubuntu).To check whether X11 forwarding is enabled, look at the value of the
DISPLAY environment variable:echo $DISPLAY . You should see a
value likelocalhost:10 (applications running on the remote machine
are told to connect to a display running on the same machine, but that
display connection is in fact forwarded by SSH to your client-side
display). Note that ifDISPLAY isn't set, it's no use setting it
manually: the environment variable is always set correctly if the
forwarding is in place. If you need to diagnose SSH connection issues,
pass the option-vvv tossh to get a detailed trace of what's
happening.If you're connecting through some other means, you may or may not be
able to achieve X11 forwarding. If your client is running Windows,
PuTTY
supports X11 forwarding; you'll have to run an X server on the Windows
machine such as Xming.By Gilles from askubuntu
如果您想在远程主机上使用xclip,只需在-ssh命令中添加-X
1 | ssh user@host -X |
可以在这里找到更多详细信息:https://askubuntu.com/a/305681
试试这个,它会像魅力一样工作。我遇到了同样的错误,但是这种方法对我有用:
1 | ssh USER@REMOTE"cat file"|xclip -i |
阅读了您链接的文档。太傻了!
如果您不是从图形X会话内部进行工作,则需要将
1 | DISPLAY=:0 xclip -sel clip < ~/.ssh/id_rsa.pub |
当然
以下内容也对我有用:
1 | ssh <user>@<host> "cat <filepath>"|pbcopy |
由用户root添加此命令:
ssh user_to_acces @ hostName -X
user_to_acces =用户
hostName =主机名机器