Git:添加SSH公钥
1. 生成SSH密钥
ssh-keygen -t rsa -C "your email"
# 会有如下提示
# 1.请输入生成密钥路径和文件名
# Enter file in which to save the key (C:\Users\{username}/.ssh/id_rsa):
# 2.输入密钥密码
# Enter passphrase (empty for no passphrase):
# 3.确认密钥密码
# Enter same passphrase again:
注意生成的私钥一定要放到C:\Users\{username}/.ssh/
下面
2. 添加公钥到github
将公钥(默认id_rsa.pub)内容复制添加到网页当前,Titlte可以随意输入
3. 测试
ssh -T git@github.com
# 如果提示如下代表成功
# Hi {yourname}! You've successfully authenticated, but GitHub does not provide shell access.
4. 配置多个SSH密钥
.ssh下创建config文件
例
#gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
#github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github