ssh 公鑰生成
生成, 默認(rèn)文件名為id_rsa
ssh-keygen -t rsa -C "your_email@example.com"
多個(gè)key的情況, second為文件名稱
ssh-keygen -t rsa -C "your_email@example.com" -f ~/.ssh/second
服務(wù)端配置
將生成的xxx.pub的內(nèi)容拷貝到對(duì)應(yīng)的網(wǎng)站中
ssh config 配置. ~/.ssh/config
- Host >域名
- User >用戶名
- IdentityFile >ssh key的路徑
- IdentitiesOnly >只使用這里設(shè)置的key, 防止使用默認(rèn)的
- 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
連接測(cè)試
ssh -T git@github.com
git 名稱設(shè)置
git config --global user.name "User name"
git config --global user.email user@example.com
如果不設(shè)置全局的, 在項(xiàng)目目錄下執(zhí)行, 去掉--global即可