ssh报错:no such identity: /xxx/xxx/.ssh/id_rsa: No such file or directory解决方案

ssh报错:no such identity: /xxx/xxx/.ssh/id_rsa: No such file or directory.Permission denied (publickey)解决方案

最近在使用ssh方式连接公司跳板机时报错:

Warning: Permanently added 'xxx' (ECDSA) to the list of known hosts.
no such identity: /xxx/xxx/.ssh/id_rsa: No such file or directory
no such identity: /xxx/xxx/.ssh/id_dsa: No such file or directory
no such identity: /xxx/xxx/.ssh/id_ecdsa: No such file or directory
Permission denied (publickey).

之前在Win上使用是正常的,从Win上复制到Mac之后,ssh连接报这个错误。网上找了很多方法,虽然很有道理,也应该能覆盖满多错误场景了,但是很遗憾没有覆盖我本次的错误场景。

后来进行分析之后,解决了上述问题,也给大家一个遇到上述问题的一个参考解决方案。

解决方式:

利用自己电脑的 ssh-agent 的工具比如 ssh-add 加好自己的 key

ssh-add 私钥

ssh-add 是一个命令行工具,用于将 SSH 私钥添加到 SSH 代理中。SSH 代理是一个在后台运行的进程,可以管理和存储 SSH 密钥,以便在 SSH 连接时自动提供它们,而无需用户手动输入密码。

具体来说,ssh-add 命令可以将指定的私钥添加到 SSH 代理中,使得该私钥在后续的 SSH 连接中可用。如果私钥已经被添加到代理中,则 ssh-add 命令只会将该私钥从磁盘中删除,而不会从代理中删除。

例如,要将名为 id_rsa 的私钥添加到 SSH 代理中,可以使用以下命令:

ssh-add ~/.ssh/id_rsa

在执行此命令后,系统会提示您输入私钥的密码,以便将其添加到 SSH 代理中。如果密码正确,私钥将被添加到代理中,并且以后的 SSH 连接将自动使用该私钥进行身份验证。

需要注意的是,ssh-add 命令只会将私钥添加到当前的 SSH 代理中。如果没有运行代理,或者代理已经退出,则需要重新运行 ssh-agent 命令来启动 SSH 代理。

这一步应该是在使用ssh连接前需要做的一步,而我遗漏了。但我实际上我在连接时也使用命令ssh -i ~/.ssh/private_key来指定了私钥,不知道为什么是因为没生效吗?后面还需要再抽时间详细研究下,现在先记录下这个问题,提供一种可能的解决方案。

执行后,再次使用ssh即可连接远程主机

另外,附在排错过程中遇到的一些好的解决方案,应该也能覆盖另外大部分一些场景:

[SSH: “no such identity”](https://superuser.com/questions/581809/ssh-no-such-identity)

[SSH Suddenly returning Invalid format]

[GIT no such identity: id_rsa: No such file or directory]

Warning: Identity file id_rsa not accessible: No such file or directory.

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JermeryBesian

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值