生成 rsa key
打开PowerShell
#切换到当前用户目录
cd $env:USERPROFILE
#添加.ssh文件夹
mkdir .ssh
cd .ssh
#生成 rsa 文件
ssh-keygen -t rsa -C "your@mail.com"
#填入文件名字会生成相应的文件名
#例如:rsa_github 会生成 rsa_github 和 rsa_github.pub
编写配置文件 config
添加配置文件同样是用户目录下的.ssh
文件夹,添加config
文件
cd $env:USERPROFILE/.ssh
notepad config
Host github.com
HostName github.com
IdentityFile ~/ssh/rsa_github
PreferredAuthentications publickey
User yourname
Host gitee.com
HostName gitlab.com
IdentityFile ~/.ssh/rsa_gitlab
PreferredAuthentications publickey
User yourname
添加到Github并测试
- 将 res_github.pub 的内容添加到 Github 即可
Github 添加 SSH key - 测试与 Github 的连接
Github 测试 SSH 连接
ssh -T git@github.com
如果有需要接受 RSA key fingerprint,yes 接受。
然后正常情况应该像下面这样:
Hi alluLinger! You've successfully authenticated, but GitHub does not provide shell access.
Gitlab, Gitee 等同理