我想在多台机器上,使用一对 rsa 去管理云服务器,操作如下
Host yun HostName xxx(我自己的 ip) IdentityFile ./aliyun Port 22 User root Host github HostName github.com IdentityFile ./github User git Host gitee HostName gitee.com IdentityFile ./gitee User git
登陆,提示成功
但是我同样的操作,生成 github 秘钥对的时候,却在另一台机器无法同步代码,大佬们,这是什么情况?
配置文件还是上面的
输入 ssh -T github
控制台打印 :Hi skrbug! You've successfully authenticated, but GitHub does not provide shell access.
拉取项目,提示: [email protected]: Permission denied (publickey).
还有两个坑,来补充下... 以防有 V 友按照上面方法依然不成功
eval "$(ssh-agent -s)" ssh-add
即最终配置文件
Host aliyun HostName 云服务器的ip IdentityFile /home/skrbug/.ssh/aliyun Port 22 User root Host * HostName github.com IdentityFile /home/skrbug/.ssh/github User git Host * HostName gitee.com IdentityFile /home/skrbug/.ssh/gitee User git Host centos HostName 192.168.207.128 Port 22 User root
参考帖子: https://blog.csdn.net/zcc_heu/article/details/79017606 https://www.cnblogs.com/ailhc/p/6586465.html
![]() | 1 Gav1n OP 已解决,把配置文件改成这样的就好了。 ``` Host * HostName github.com IdentityFile ./github User git Host * HostName gitee.com IdentityFile ./gitee User git ``` 主题不知道从哪里删... |
![]() | 2 indev 2019-12-22 15:32:22 +08:00 via Android skrbug |
![]() | 3 Gav1n OP 还有两个坑,来补充下... 以防有 V 友按照上面方法依然不成功 1. IdentityFile,不要写相对路径,一开始我是认为 win 无法用./ 这个路径写法,转而换成.\ 发现依然报错. 后来切换成 ubuntu,书写 aliyun 依然报错,故不要写相对路径 2. 权限问题,拷贝到其他系统时,权限不可以设置成 777, 而是要改成 600,切记! 这是硬性要求,也是处于安全考虑. 3. 如果设置完毕后,没有生效,执行下此命令(推测是起到刷新 ssh 缓存的作用). eval "$(ssh-agent -s)" ssh-add 参考帖子: https://blog.csdn.net/zcc_heu/article/details/79017606 https://www.cnblogs.com/ailhc/p/6586465.html |
4 lostpg 分享下自己配置 ssh 的填坑路: - 在 zshrc/bashrc 中添加 ssh-agent 的 auto setup,我用的 [M$ vscode 的 ssh-agent 启动脚本]( https://code.visualstudio.com/docs/remote/troubleshooting#_setting-up-the-ssh-agent) 的配置,并将 `.ssh/ssh-agent` 改成绝对路径。( zsh 再添上 `zstyle ':completion:*:ssh:*' hosts off` 让 ssh 不使用 `/etc/hosts/` 内网址做补全候选) - 所有公私钥都不用默认名,在 ssh config 中添加对应的条目,把每一条主机配置都加上 `addKeysToAgent yes` (因为我私钥有 passphrase )。 这样,配合 ssh-agent,所有有 passphrase 的私钥,只需要第一次使用密钥时(而不是第一次登录 shell )输入 passphrase,之后都免密登录。重启失效。 |