git push命令:
git remote add origin {远程地址}
git push origin master
新建user1、user2的SSH Key
#新建user1 SSH key:
$ cd ~/.ssh
# 切换到C:\Users\Administrator\.ssh
#ssh-keygen -t rsa -C "user1@email.com"
一路回车即可;
# 新建user2的SSH key
#ssh-keygen -t rsa -C "user2@email.com"
# 设置名称为Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): /c/Users/Administrator/.ssh/id_rsa_user2
接下来一路回车不设置密码
密钥添加到SSH agent中
因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
ssh-add ~/.ssh/id_rsa_user2
如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:
eval `ssh-agent -s`ssh-add ~/.ssh/id_rsa_user2
将ssh key 添加到github账号中
clip< ~/.ssh/id_rsa_user2.pub 拷贝sshkey到剪切板
打开github网页,添加ssh key,复制进去。
修改config文件
在~/.ssh目录下找到config文件,如果没有就创建:
touch config
然后修改我的config配置如下:
Host github.comHostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Host github2
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_user2
测试
$ ssh -T git@github.com
Hi XXXX! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@github2
Hi XXXX! You've successfully authenticated, but GitHub does not provide shell access.
--------------------------PS ---------------------
用以上方法成功使用上了自己的Github账号clone项目,但是两条都提示的是我自己的账号,明明设置了其中一个是工作账号的。。。。不过好在工作账号也没啥需要访问上去的必要。