怎么生成ssh密钥并于github关联
时间: 2024-05-12 21:20:39 浏览: 79
SSH密钥是用于身份验证的一种方式,可以用于连接GitHub,下面是生成和关联SSH密钥的步骤:
1. 打开终端(MacOS和Linux)或Git Bash(Windows)。
2. 输入以下命令,生成SSH密钥:
```
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```
其中,your_email@example.com是你的GitHub注册邮箱,可以自己替换。
3. 按照提示输入文件保存路径和密码(可以不设置密码)。
4. 在终端中输入以下命令,将SSH代理添加到ssh-agent中:
```
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
```
其中,~/.ssh/id_rsa是你生成的SSH密钥文件路径,可以根据自己的实际情况修改。
5. 在GitHub上,点击右上角的头像,进入“Settings”页面。
6. 在左侧菜单栏中选择“SSH and GPG keys”。
7. 点击“New SSH key”按钮,填写Title和Key,将你生成的SSH密钥复制到Key中。
8. 点击“Add SSH key”按钮,完成SSH密钥和GitHub的关联。
现在,你就可以使用SSH密钥连接GitHub了。在终端中输入以下命令测试:
```
ssh -T git@github.com
```
如果显示“Hi username! You've successfully authenticated, but GitHub does not provide shell access.”,则说明连接成功。
阅读全文
相关推荐


















