将公钥发送到远程主机的命令

发布于 2024-11-28 11:07:06 字数 66 浏览 4 评论 0原文

我记得有一个命令可以将公钥发送到我想要的远程主机。我想使用该功能将我的一个公钥发送到另一台主机。我怎样才能做到这一点?

I remember there is a command to send public key to the remote host that I want. I want to use that feature to send one of my public keys to the other host. How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

百善笑为先 2024-12-05 11:07:06

您正在寻找ssh-copy-id。此命令所做的只是创建 .ssh.ssh/authorized_keys 并相应地设置它们的权限(如果它们不存在)。然后它将您的公钥附加到 .ssh/authorized_keys 的末尾。

You are looking for ssh-copy-id. All this command does is create .ssh and .ssh/authorized_keys and set their permissions appropriately if they don't exist. Then it appends your public key to the end of .ssh/authorized_keys.

献世佛 2024-12-05 11:07:06

您可能正在寻找此命令:

cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'

它将您的公钥附加到服务器授权的密钥上。

来源

You might be looking for this command:

cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'

It appends your public key to the servers authorized keys.

Source

别挽留 2024-12-05 11:07:06

如果您的服务器已设置为不接受基于密码的登录,您可能会收到权限被拒绝(publickey)错误。

这是使用 netcat 发送密钥的另一种方法,因此您无需进行身份验证。它只能在本地网络上运行,但您可以使用端口转发在互联网上执行此操作。

在服务器上:

$ nc -l 55555 >> ~/.ssh/authorized_keys

在客户端上(将 HOSTNAME 替换为服务器的主机名或 IP):

$ nc HOSTNAME 55555 < ~/.ssh/id_rsa.pub

您可以将 55555 替换为您选择的开放端口。

来源:通过 lan 从 linux 到 linux 聊天?


新手附录:我认为还没有人提到过这一点,但是如果出现ERROR: failed to open ID file '/home/username/.pub': No such file,则需要先生成密钥。 Ubuntu 帮助页面有关于生成 RSA 密钥的精彩指南。

If your server is already set up to not accept password-based login, you might get a Permission denied (publickey) error.

This is another method to send the key, using netcat, so you don't have to authenticate. It will only work over a local network, but you can use port forwarding to do this over the internet.

On the server:

$ nc -l 55555 >> ~/.ssh/authorized_keys

On the client (replace HOSTNAME with the hostname or IP of the server):

$ nc HOSTNAME 55555 < ~/.ssh/id_rsa.pub

You can replace 55555 with an open port of your choice.

source: chat over lan from linux to linux?


Appendix for total newbies: I don't think anyone's mentioned this yet, but if you get ERROR: failed to open ID file '/home/username/.pub': No such file, you need to generate a key first. The Ubuntu help pages have a great guide on Generating RSA Keys.

最终幸福 2024-12-05 11:07:06

在其他答案中没有 ssh-copy-id 的示例,所以这里是(首先您需要生成密钥)

ssh-copy-id user@url

In other answers there's no example for ssh-copy-id so here it is(first you need to generate the key)

ssh-copy-id user@url
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文