Linux 无法复制 ~/.ssh/id_rsa.pub
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18695934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to copy ~/.ssh/id_rsa.pub
提问by cqcn1991
I'm following in Generating SSH Keys, it says
我正在关注Generating SSH Keys,它说
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
须藤 apt-get 安装 xclip
# 下载并安装 xclip。如果没有
apt-get
,则可能需要使用其他安装程序(如yum
)xclip -sel 剪辑 < ~/.ssh/id_rsa.pub
# 将 id_rsa.pub 文件的内容复制到剪贴板
But after I runxclip -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
但是在我运行后xclip -sel clip < ~/.ssh/id_rsa.pub
我得到了Error: Can't open display: (null)
什么问题?我用谷歌搜索,但一无所获
采纳答案by Jahdere
DISPLAY=:0 xclip -sel clip < ~/.ssh/id_rsa.pub
didn't work for me (ubuntu 14.04
), but you can use :
DISPLAY=:0 xclip -sel clip < ~/.ssh/id_rsa.pub
对我不起作用(ubuntu 14.04
),但您可以使用:
cat ~/.ssh/id_rsa.pub
to get your public key
获取您的公钥
回答by hek2mgl
Have read the documentation you've linked. That's totally silly! xclip
is just a clipboard. You'll find other ways to copy paste the key... (I'm sure)
已阅读您链接的文档。这完全是愚蠢的!xclip
只是一个剪贴板。您会找到其他方法来复制粘贴密钥...(我确定)
If you aren't working from inside a graphical X session you need to pass the $DISPLAY
environment var to the command. Run it like this:
如果您不在图形 X 会话中工作,则需要将$DISPLAY
环境变量传递给命令。像这样运行它:
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 machine it is likely that it is :0
当然,这:0
取决于您使用的显示器。如果您有一台典型的台式机,它很可能是:0
回答by Peter Pshenichny
In case you are trying to use xclip on remote host just add -X to your ssh command
如果您尝试在远程主机上使用 xclip,只需将 -X 添加到您的 ssh 命令
ssh user@host -X
More detailed information can be found here : https://askubuntu.com/a/305681
更详细的信息可以在这里找到:https: //askubuntu.com/a/305681
回答by VaTo
Try this and it will work like a charm. I was having the same error but this approach did the trick for me:
试试这个,它会像魅力一样工作。我遇到了同样的错误,但这种方法对我有用:
ssh USER@REMOTE "cat file"|xclip -i
回答by Dario
The following is also working for me:
以下也对我有用:
ssh <user>@<host> "cat <filepath>"|pbcopy
回答by Carles Alcolea
This was too good of an answernot to post it here. It's from a Gilles, a fellow user from askubuntu:
这是一个太好的答案,不能不在这里发布。它来自Gilles,来自askubuntu的一位用户:
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 line
ForwardX11 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, PuTTYsupports X11 forwarding; you'll have to run an X server on the Windows machine such as Xming.
By Gillesfrom askubuntu
剪贴板由X 服务器提供。服务器是否无头并不重要,重要的是您的本地图形会话可用于远程计算机上运行的程序。由于 X 的网络透明设计,这是可能的。
我假设您从运行 Linux 的机器上使用 SSH 连接到远程服务器。确保在客户端配置和服务器配置中都启用了 X11 转发。在客户端配置,你需要有线路
ForwardX11 yes
在~/.ssh/config
默认情况下有它,或者通过选项-X
的ssh
命令只为这届会议。在服务器配置,你需要有行X11Forwarding yes
中/etc/ssh/sshd_config
(这是默认存在在Ubuntu)。要检查是否启用了 X11 转发,请查看
DISPLAY
环境变量的值 :echo $DISPLAY
。您应该看到类似的值localhost:10
(运行在远程机器上的应用程序被告知连接到在同一台机器上运行的显示器,但该显示器连接实际上是由 SSH 转发到您的客户端显示器)。请注意,如果DISPLAY
未设置,则手动设置它是没有用的:如果转发到位,则环境变量始终设置正确。如果您需要诊断 SSH 连接问题,请传递选项-vvv
以ssh
详细跟踪正在发生的事情。如果您通过其他方式连接,您可能无法实现 X11 转发。如果您的客户端运行的是 Windows, PuTTY支持 X11 转发;您必须在 Windows 机器上运行 X 服务器,例如Xming。
作者来自 askubuntu 的Gilles
回答by Marc Stober
Based on the date of this question the original poster wouldn't have been using Windows Subsystem for Linux. But if you are, and you get the same error, the following alternative works:
根据这个问题的日期,原始海报不会使用Windows Subsystem for Linux。但是,如果您是,并且遇到相同的错误,则以下替代方法有效:
clip.exe < ~/.ssh/id_rsa.pub
Thanks to this pagefor pointing out Windows' clip.exe (and you have to type the ".exe") can be run from the bash shell.
感谢这个页面指出Windows的clip.exe(你必须输入“.exe”)可以从bash shell运行。
回答by Fadid
add by user root this command : ssh user_to_acces@hostName -X
由 root 用户添加此命令:ssh user_to_acces@hostName -X
user_to_acces = user hostName = hostname machine
user_to_acces = 用户主机名 = 主机名机器