创建非默认本地SSH密钥
GitHub不支持相同SSH Key在不同GitHub账户下使用。所以除默认账户外,需要单独为新GitHub账号建立一个SSH Key。注意,使用ssh-keygen生成新key,出现提示输入文件名的时候(Enter file in which to save the key (~/.ssh/id_rsa): id_rsa_new)要输入与默认配置不一样的文件名,比如:我这里填的是 id_rsa_new。否则会覆盖之前生成的默认key。并用ssh-add命令将新创建的Key添加到由ssh-agent 维护的列表中。
ssh-agent 是用于管理SSH private keys的, 长时间持续运行的守护进程(daemon). 唯一目的就是对解密的私钥进行高速缓存。
ssh-add 提示并将用户的使用的私钥添加到由ssh-agent 维护的列表中. 此后, 当使用公钥连接到远程 SSH 或 SCP 主机时,不再提示相关信息.
1 | ssh-keygen -t rsa -b 2048 -C "[email protected]" |
如果出现 Could not open a connection to your authentication agent 的错误,就试着用以下命令:
1 | $ ssh-agent bash |
配置SSH
配置~/.ssh/config
1 | # 默认的GitHub连接 |
测试一下
1 | ✦2 ➜ ssh -T [email protected] |
在向非默认仓库提交代码时,需要对原远程Push地址做一下转换
1 | git remote add origin [email protected]:name/hello.git |
试一下吧!