赞
踩
ssh-keygen -t rsa -C "one@qq.com"
//接下来回车两次
/*第一次其实是让输生成密钥的名字,生成后放后你git命令所在的目录
效果同2.生成密钥
第二次是让输入密码,因为并不机密所以可以空着直接回车就好
*/
ssh-keygen -t rsa -C "two@qq.com" -f /c/Users/Administrator/.ssh/id_rsa_two
.pub的是公钥,其它两个是私钥不能泄漏给他人
id_rsa
id_rsa.pub
id_rsa_two
id_rsa_two.pub
ssh-agent bash //如果不能执行以下两句
ssh-add ~/.ssh/id_rsa_tow //linux用这个
ssh-add id_rsa_two //windows用这个
//显示:
//Identity added: id_rsa_two (two@qq.com)
ssh-add -l
来确认结果说明:
# 注释
Host 为域名别名
Hostname:真实地址
User:用户名
IdentityFile:rsa存放地址
# 默认github账号
Host github
HostName github.com
IdentityFile C:\Users\Administrator\.ssh\id_rsa
# github账号2
Host github_two
HostName github.com
IdentityFile C:\Users\Administrator\.ssh\id_rsa_two
#默认github账号
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
# github账号2
Host github_two
HostName github.com
IdentityFile ~/.ssh/id_rsa_two
$ ssh -T git@github
# Hi sky! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@github_two
# Hi sky_two! You've successfully authenticated, but GitHub does not provide shell access.
命令:git remote add origin git@github_two:xxxx/test.git
#本地建库
$ git init
$ git commit -am "first commit'
#push到github上去
$ git remote add origin git@github_two:xxxx/test.git
$ git push origin master
使用 git config --list
查看当前配置。
如果你之前在设置本地仓库和github连接的时候设置过user.name和user.email,那么你必须首先清除掉该设置,因为不清除掉该设置,两个账号在提交资料的时候,验证肯定冲突。
只能设置一个全局的user.name和user.email,而你现在有两个账号。
【清除全局】:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git config user.name 'sky_two'
$ git config user.email 'sky_two@qq.com'
git remote add origin git@github_two:xxxx/test.git
之后操作和一个账号就一样了
GitHub提供了两种方法来保护我们的邮箱隐私:使用GitHub专用的替代邮箱
如果勾选第1项,且不勾选第2项,要push成功,git这样设置:
$ git config user.email "sky_one@gmail.com"
$ git config user.name "sky_one"
$ git config user.email "sky_two@126.com"
$ git config user.name "sky_two"
git设置的邮箱尽量和github的邮箱保持一致
如果勾选第2项,要push成功,要么去掉第一项勾选,要么把修改git设置:
$ git config user.email "sky_one@users.noreply.github.com"
$ git config user.name "sky_one"
$ git config user.email "sky_two@users.noreply.github.com"
$ git config user.name "sky_two"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。