南飓风 发表于 2024-6-9 14:53:29

【服务器】SSH 私钥报错 Permissions for ‘id_rsa‘ are too open. It is

报错信息

Permissions for 'id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "id_rsa": bad permissions
xxx@xxx: Permission denied (publickey).
问题描述

(发现XShell自带的公私钥天生工具,天生的公私钥对不好使)
使用ssh-keygen
天生公私钥对之后,直接在cmd命令行中举行连接:
ssh-keygen
得到
https://img-blog.csdnimg.cn/7b6a41e350a444b189279bdef7c70016.png
将公钥添加到服务器的authorized_keys之后,
ssh username@hostname -p 17022 -i id_rsa
报错如下
https://img-blog.csdnimg.cn/b793c1c1aeba44a6889521023dc488e0.png
Permissions for 'id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "id_rsa": bad permissions
xxx@xxx: Permission denied (publickey).
办理办法

重要是因为本地的私钥文件 id_rsa 的权限太开放了
Windows情况下

在Windows本地情况下:
右键id_rsa文件 → 属性 → 高级
https://img-blog.csdnimg.cn/8ca25729286d496db047b559becf6336.png
点击“禁用继承”
https://img-blog.csdnimg.cn/258aa574cd5646c19a344d8e3f1233d8.png
点击 “将已继承的权限转换为此对象的显式权限。”
https://img-blog.csdnimg.cn/b6300b9ece624b51abb0d8ad8f845a99.png
之后情况如下:
https://img-blog.csdnimg.cn/58fc6a06da964521b212a05fbcb7ba95.png
然后把全部用户和组的权限都删除:
https://img-blog.csdnimg.cn/d256f0c9f7714feba220a78edb730347.png
https://img-blog.csdnimg.cn/801429e9c69a4cffa4e41eac8faa7383.png
再点击 “添加”
https://img-blog.csdnimg.cn/321fd97d7f1a4969ade7955f5327988e.png
输入当前的主机用户名(比方juruo),点击确定
https://img-blog.csdnimg.cn/889bc8e3a60048dbbc37db83b412f7ee.png
看到 “主体”跟之前的 id_rsa文件的 全部者 保持同等
https://img-blog.csdnimg.cn/903fb90cb1f04c05a30673208dbd8221.png
https://img-blog.csdnimg.cn/a2489eb37e3a49178ea8d3f94b46ecce.png
https://img-blog.csdnimg.cn/b93881e067d44ba2965a80f74301bae4.png
点击 应用:
https://img-blog.csdnimg.cn/ebfcd9bc23fd427795715c95789dd750.png
之后就可以正常使用id_rsa这个私钥了:
https://img-blog.csdnimg.cn/6b3aed5a0c9742faba14d51deef79507.png
Linux情况下

在Linux本地情况下:
chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
参考:https://blog.csdn.net/IBLiplus/article/details/102405792

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 【服务器】SSH 私钥报错 Permissions for ‘id_rsa‘ are too open. It is