ssh-copy-id没有发现身份错误

use*_*975 60 unix ssh ssh-keys

我有几个客户端系统,我需要推送ssh密钥并从我的服务器登录而无需身份验证提示.

首先,在服务器上,我创建了ssh密钥,如下所示,这是成功的

]# ssh-keygen -t rsa -N "" -f my.key
Run Code Online (Sandbox Code Playgroud)

其次,尝试复制pub键但失败,没有身份错误.我在这里做错了吗?

]# ssh-copy-id my.key.pub 10.10.1.1
/usr/bin/ssh-copy-id: ERROR: No identities found
Run Code Online (Sandbox Code Playgroud)

Jos*_*lly 55

你需要使用-i标志:

ssh-copy-id -i my.key.pub 10.10.1.1
Run Code Online (Sandbox Code Playgroud)

手册页:

如果给出-i选项,则使用身份文件(默认为〜/ .ssh/id_rsa.pub),无论ssh-agent中是否有任何键.否则,如果这样:ssh-add -L提供任何输出,它会优先使用它来识别身份文件

  • 我尝试使用-i选项并成功将键推送到目标.还验证了authorized_keys文件,密钥似乎在那里..然后我尝试ssh root@10.10.1.1但仍然提示输入密码..这里还有什么需要的.?ssh-copy-id -i my.key.pub 10.10.1.1现在尝试使用"ssh '10 .10.1.1'"登录到机器,并检入:.ssh/authorized_keys以确保我们没有添加额外的密钥那是你没想到的.〜] #ssh root@10.10.1.1 root@10.10.1.1的密码: (3认同)
  • 默认情况下,ssh在`〜/ .ssh`中查找您的密钥等.由于您的`my.key`文件似乎在另一个目录中,请尝试`ssh -i /location/of/my.key 10.10.1.1`(或考虑将my.key文件移动到`〜/ .ssh`) (2认同)

SMS*_*MSM 26

运行以下命令

# ssh-add
Run Code Online (Sandbox Code Playgroud)

如果它出现以下错误:无法打开与身份验证代理的连接

要删除此错误,请运行以下命令:

# eval `ssh-agent`
Run Code Online (Sandbox Code Playgroud)

  • 执行eval`ssh-agent`后执行ssh-add然后执行ssh-copy-id,一切都应该正常工作. (4认同)
  • 谢谢!我一直在试图找出什么不起作用,但这解决了它 (2认同)

小智 24

在客户端生成ssh密钥为我解决了它

$ ssh-keygen -t rsa
Run Code Online (Sandbox Code Playgroud)

  • 我想说这是适用于通常情况的(在默认位置创建 SSH 密钥) (2认同)
  • 只是“ssh-keygen”对我有用。无需指定 `-t rsa` 。 (2认同)

小智 15

最简单的方法是:

ssh-keygen
[enter]
[enter]
[enter]

cd ~/.ssh
ssh-copy-id -i id_rsa.pub USERNAME@SERVERTARGET
Run Code Online (Sandbox Code Playgroud)

阿特:

它非常非常简单。

在“ss-keygen”手册中解释:

"DESCRIPTION ssh-keygen 为 ssh(1) 生成、管理和转换认证密钥。ssh-keygen 可以创建供 SSH 协议版本 1 使用的 RSA 密钥和供 SSH 协议版本 2 使用的 DSA、ECDSA 或 RSA 密钥。使用 -t 选项指定要生成的密钥。 如果不带任何参数调用,ssh-keygen 将生成一个 RSA 密钥,用于 SSH 协议 2 连接。


Gur*_*uru 9

ssh-copy-id无法找到系统中ssh-keygen生成的id_rsa.pub文件,请使用以下命令完成:

  1. 找到.pub文件的路径: locate *.pub
  2. 复制路径(例如:/home/user_name/.ssh/id_rsa.pub)并运行以下命令: ssh-copy-id -i /home/user_name/.ssh/id_rsa.pub hostname


小智 6

Old post but I came up with this problem today, ended up googling and had found myself here. I had figured it out on my own but thought I'd share my issue & solution in my case to help out anyone else who may have the same issue.

Issue:

[root@centos [username]]# ssh-keygen -t rsa
Run Code Online (Sandbox Code Playgroud)

Enter file in which to save the key (/root/.ssh/id_rsa):I HAD JUST HIT ENTER

/usr/bin/ssh-copy-id: ERROR: No identities found
Run Code Online (Sandbox Code Playgroud)

Solution:

Enter file in which to save the key (/root/.ssh/id_rsa): **/home/[username]/id_rsa**
Run Code Online (Sandbox Code Playgroud)

Be sure if you are doing this as root you are coping the key into the user directory you wish to login with. NOT the root user directory.

执行此操作时,我正在 SSH 到机器中,所以我猜 ssh-copy-id 只是指向您默认登录的目录。

希望这可以帮助任何人。


Dan*_*ida 6

在使用我从其他地方手动复制的私钥的现有帐户上遇到了这个。所以错误是因为缺少公钥

所以只需从私人生成一个

 ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)


Ash*_*sle 5

您需要使用-i选项指定密钥。

ssh-copy-id -i your_public_key user@host
Run Code Online (Sandbox Code Playgroud)

谢谢。