生成ssh-key
ssh-keygen -t rsa -C "it@github.com" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -C "it@gitlab.com" -f ~/.ssh/gitlab_rsa
ssh-keygen -t rsa -C "it@gitee.com" -f ~/.ssh/gitee_rsa
配置 ssh-config
touch ~/.ssh/config
Host github.com
User github_user
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_rsa
Host gitlab.com
User gitlab_user
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_rsa
Host gitee.com
User gitee_user
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_rsa
配置 ssh-agent
eval $(ssh-agent -s)
ssh-add ~/.ssh/github_rsa
ssh-add ~/.ssh/gitlab_rsa
ssh-add ~/.ssh/gitee_rsa
配置 .gitconfig
git config --global user.name "github_user"
git config --global user.email "it@github.com"
git config --global user.name "gitlab_user"
git config --global user.email "it@gitlab.com"
git config --global user.name "gitee_user"
git config --global user.email "it@gitee.com"
上传 public-key
pbcopy < ~/.ssh/github_rsa.pub
pbcopy < ~/.ssh/gitlab_rsa.pub
pbcopy < ~/.ssh/gitee_rsa.pub
验证SSH
ssh -T git@github.com
ssh -T git@10.1.128.18
ssh -T git@gitee.com
"Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access."
"Welcome to GitLab, (xxxx)!"
"Hi xxxx! You've successfully authenticated, but Gitee does not provide shell access."
"git@github.com: Permission denied (publickey)."
// GitLab
"git@gitlab.com: Permission denied (publickey,keyboard-interactive)."
// Gitee
"git@gitee.com: Permission denied (publickey)."