有时候因为自己需要,可能要在一台电脑上设置多个GIthub账号要在同一台电脑上给两个属于不同账号的仓库提交时。但是一把公钥只能被一个GITHUB账号拥有,因此必须为不同的账号创建不同的公钥进行配对。 方法步骤: 1.制作公钥 制造第一把公钥: ssh-keygen -t rsa -C "yq08051035@163.com" # 设置名称为id_rsa Enter file in which to save the key (.ssh/id_rsa): id_rsa ![]() 制造第二把公钥: ssh-keygen -t rsa -C "yq08051035@gmail.com" # 设置名称为my Enter file in which to save the key (.ssh/id_rsa): my ![]() -------------------------------- 2.把id_rsa.pub添加到后台SSH账户 查看文件是否存在 ![]() 将id_rsa.pub添加到yq08051035@163.com账号的后台ssh。 将my.pub添加到yq08051035@gmail.com账号的后台ssh。 ![]() 3.在.ssh目录下配置config文件 Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Host my.github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/my 4.测试 ssh -T git@github.com Hi yeching! You've successfully authenticated, but GitHub does not provide shell access. ![]() ssh -T git@my.github.com Hi aifusheng! You've successfully authenticated, but GitHub does not provide shell access. 说明OK。 ![]() 当我们要在一个仓库上PUSH提交的内容时,先解析出仓库地址,然后从该仓库的所属账号中找到一把能解锁该提交的公钥。 |
|