添加用户名和邮箱

1
2
3
4
5
6
7
8
# 设置邮箱(zsyyblog@qq.com要与gitlab用户配置的邮箱一致)
git config --global user.email "zsyyblog@qq.com"

# 设置用户名
git config --global user.user "zsyyblog"

# 查看是否设置成功
git config --list

生成ssh密钥

1
2
3
4
5
6
ssh-keygen.exe -t ras -C "zsyyblog@qq.com"

# 查看是否生成成功
cd ~/.ssh
ls
id_rsa id_rsa.pub known_hosts

网页端配置

1
2
# 查看is_rsa.pub内容并拷贝内容至GitHub SSH Keys配置端
cat is_rsa.pub

需要将公钥的内容复制至github的SSH配置中。

增加配置

1
vim ~/.ssh/config

添加以下配置:

1
2
3
4
5
6
7
#添加
Host github.com
identityFile ~/.ssh/id_rsa #填写自己的私钥文件名
Host github.com
Hostname ssh.github.com
Port 443
User git

测试验证

1
git clone url.git

或者使用以下命令:

1
ssh -T git@github.com