git ssh 配置
添加用户名及邮箱到 git 的全局配置
1
2
3
4
5
git config --global user.name "Your Name Here"
# Sets the default name for git to use when you commit
git config --global user.email "your_email@example.com"
# Sets the default email for git to use when you commit
生成 ssh 密钥文件(已有证书就忽略
1. 邮箱改成你的 github 邮件,根据提示操作创建密钥
1
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
2. 提示 nter a file in which to save the key,
输入文件保存的路径,直接回车就保存到提示的目录
1
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
3. 如果需要添加密码就在出现下面提示时输入
1
2
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
设置 ssh
1. 修改 /etc/ssh/ssh_config
, 在文件末尾添加
1
2
3
4
Host github.com
User git
Hostname github.com
IdentityFile /etc/ssh/github-ecdsa-521
2. 将公钥添加到 github 帐户
- 复制公钥文件到剪贴板
1
2
clip < /etc/ssh/github-ecdsa-521.pub
# Copies the contents of the id_rsa.pub file to your clipboard
- 然后点击 你的头像 ->
Setting
->SSH and GPG keys
->New SSH key
-> 取个名字,粘贴上公钥 ->Add SSH key
3. 用命令测试一下
1
ssh -T git@github.com
如果提示信息里面能看到你的用户名就说明成功了
参考
-= 完 =-
本文由作者按照 CC BY 4.0 进行授权