ssh報錯:no such identity: /xxx/xxx/.ssh/id_rsa: No such file or directory.Permission denied (publickey)解決方案
最近在使用ssh方式連接公司跳板機(jī)時報錯:
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上復(fù)制到Mac之后,ssh連接報這個錯誤。網(wǎng)上找了很多方法,雖然很有道理,也應(yīng)該能覆蓋滿多錯誤場景了,但是很遺憾沒有覆蓋我本次的錯誤場景。
后來進(jìn)行分析之后,解決了上述問題,也給大家一個遇到上述問題的一個參考解決方案。
解決方式:
利用自己電腦的 ssh-agent 的工具比如 ssh-add 加好自己的 key
ssh-add 私鑰
ssh-add
是一個命令行工具,用于將 SSH 私鑰添加到 SSH 代理中。SSH 代理是一個在后臺運(yùn)行的進(jìn)程,可以管理和存儲 SSH 密鑰,以便在 SSH 連接時自動提供它們,而無需用戶手動輸入密碼。具體來說,
ssh-add
命令可以將指定的私鑰添加到 SSH 代理中,使得該私鑰在后續(xù)的 SSH 連接中可用。如果私鑰已經(jīng)被添加到代理中,則ssh-add
命令只會將該私鑰從磁盤中刪除,而不會從代理中刪除。例如,要將名為
id_rsa
的私鑰添加到 SSH 代理中,可以使用以下命令:ssh-add ~/.ssh/id_rsa
在執(zhí)行此命令后,系統(tǒng)會提示您輸入私鑰的密碼,以便將其添加到 SSH 代理中。如果密碼正確,私鑰將被添加到代理中,并且以后的 SSH 連接將自動使用該私鑰進(jìn)行身份驗(yàn)證。
需要注意的是,
ssh-add
命令只會將私鑰添加到當(dāng)前的 SSH 代理中。如果沒有運(yùn)行代理,或者代理已經(jīng)退出,則需要重新運(yùn)行ssh-agent
命令來啟動 SSH 代理。
這一步應(yīng)該是在使用ssh連接前需要做的一步,而我遺漏了。但我實(shí)際上我在連接時也使用命令ssh -i ~/.ssh/private_key
來指定了私鑰,不知道為什么是因?yàn)闆]生效嗎?后面還需要再抽時間詳細(xì)研究下,現(xiàn)在先記錄下這個問題,提供一種可能的解決方案。
執(zhí)行后,再次使用ssh即可連接遠(yuǎn)程主機(jī)
另外,附在排錯過程中遇到的一些好的解決方案,應(yīng)該也能覆蓋另外大部分一些場景:
[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]文章來源:http://www.zghlxwxcb.cn/news/detail-670346.html
Warning: Identity file id_rsa not accessible: No such file or directory.文章來源地址http://www.zghlxwxcb.cn/news/detail-670346.html
到了這里,關(guān)于ssh報錯:no such identity: /xxx/xxx/.ssh/id_rsa: No such file or directory解決方案的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!