ssh 公钥生成
生成, 默认文件名为id_rsa
ssh-keygen -t rsa -C "your_email@example.com"
多个key的情况, second为文件名称
ssh-keygen -t rsa -C "your_email@example.com" -f ~/.ssh/second
服务端配置
将生成的xxx.pub的内容拷贝到对应的网站中
ssh config 配置. ~/.ssh/config
- Host >域名
- User >用户名
- IdentityFile >ssh key的路径
- IdentitiesOnly >只使用这里设置的key, 防止使用默认的
- ServerAliveInterval >连接保持
- ControlMaster auto >不用重新登录
- ControlPath ~/.ssh/master-%r@%h:%p
Host github.com
User git
IdentityFile ~/.ssh/id_gmail
IdentitiesOnly yes
Host bitbucket.org
User git
IdentityFile ~/.ssh/id_gmail
IdentitiesOnly yes
Host git.coding.net
User git
IdentityFile ~/.ssh/id_gmail
IdentitiesOnly yes
Host git.oschina.net
User git
IdentityFile ~/.ssh/id_gmail
IdentitiesOnly yes
Host *.alibaba-inc.com
User git
IdentityFile ~/.ssh/id_rsa
Host *
ServerAliveInterval 60
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
保存
ssh-add -K ~/.ssh/id_gmail
连接测试
ssh -T git@github.com
git 名称设置
git config --global user.name "User name"
git config --global user.email user@example.com
如果不设置全局的, 在项目目录下执行, 去掉--global即可