git配置公钥
1. 生成公钥
ssh-keygen -t rsa -C username@github.com
此时,~目录下会生成密钥文件 id_rsa 和公钥文件 id_rsa.pub
将id_rsa和id_rsa.pub移入 ~/.ssh目录
2. 保存凭证
在~下
git credential-store --file ~/.git-credentials store
protocol=https
host=github.com
username=username
password=password
(两次回车结束输入)
~下会生成 .git-credentials和 .gitconfig两个文件
编辑 .gitconfig
[user]
name = username
email = email@host
[credential]
helper = store
验证是否成功
git credential-store --file ~/.git-credentials get
protocol=https
host=github.com
(两次回车结束输入)
将显示:
username=username
password=password
3 将公钥添加到github
打开github.com,进入 profile -> SSH and GPG keys -> New SSH key
将 ~/.ssh/id_rsa.pub 内容复制进文本框,取个名字保存
验证是否成功
ssh -T git@github.com
显示:
Hi oblind! You've successfully authenticated, but GitHub does not provide shell access.
评论