生成SSH公钥
ssh-keygen -t rsa -C "youremail@xxx.com"
查看本机ssh
cat ~/.ssh/id_rsa.pub
一台电脑上有一个ssh key,在github上提交代码,由于其他原因
你可能会在一台电脑上提交到不同的github上,怎么办呢…
假设你电脑上一个ssh key都没有,如果有默认的一个了,请直接生成第二个
一、生成并添加第一个ssh key
$ ssh-keygen -t rsa -C "youremail@xxx.com"
在Git Bash中执行命令一路回车,会在~/.ssh/目录下生成id_rsa和id_rsa.pub两个文件
用文本编辑器打开id_rsa.pub里的内容,在Github中添加SSH Keys
不明白的请参考GitHub创建SSH Keys
二、生成并添加第二个ssh key
$ ssh-keygen -t rsa -C "youremail@xxx.com"
这次不要一路回车了,给这个文件起一个名字 不然默认的话就覆盖了之前生成的第一个
假如起名叫my,目录结构如下:
如果生成的第二个ssh key不在.ssh/下,可移动到此目录
三、在.ssh/下创建config文件 内容如下:
Host gitlab.com User 你的邮箱 Hostname ssh.gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 443 Host github.com User 你的邮箱 Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/my Port 443
from:http://blog.csdn.net/itmyhome1990/article/details/42643233