Git SSH Key生成
Git SSH Key生成
SSH Key是一种加密的公钥私钥对,用于身份验证。
使用Git通过SSH拉取远程仓库时,出现以下内容:
1 | $ git clone git@******.com:********.git |
这是因为Git需要SSH Key来验证身份,而你没有配置SSH Key。
- 首先,检查是否已有SSH Key。
1 | ls -al ~/.ssh |
如果存在id_rsa.pub文件,则说明已有SSH Key。
- 如果没有SSH Key,则生成SSH Key。
1 | ssh-keygen -t rsa -C "your_email@example.com" |
- 然后,将SSH Key添加到ssh-agent。
1 | ssh-add ~/.ssh/id_rsa |
如果出现"Could not open a connection to your authentication agent.",则说明没有安装SSH Key。请安装并配置SSH Key。
1 | eval "$(ssh-agent -s)" |
如果出现以下内容,则说明SSH Key添加成功:
1 | ssh-add ~/.ssh/id_rsa |
再次执行
1 | ssh-add ~/.ssh/id_rsa |
- 将SSH Key添加到GitHub上,以便Git通过SSH拉取远程仓库。
步骤:Settings
->SSH and GPG keys
->New SSH Key
->Title
->Key
->Add SSH Key
查看公钥,以便复制到GitHub上。
1 | cat ~/.ssh/id_rsa.pub |
- 最后,测试SSH Key是否配置成功。
1 | ssh -T git@github.com |
- 如果出现以下内容,则说明配置成功。
1 | Hi *! You've successfully authenticated, but GitHub does not provide shell access. |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 怪咖`Blog!
评论
WalineTwikoo