生成SSH密钥
如果还没有 SSH 密钥,则必须生成新的 SSH 密钥以用于身份验证。如果不确定是否已具有 SSH 密钥,可以检查现有密钥。有关详细信息,请参阅"检查现有 SSH 密钥"。
如果要使用硬件安全密钥向 GitHub 进行身份验证,则必须为硬件安全密钥生成新的 SSH 密钥。使用密钥对进行身份验证时,必须将硬件安全密钥连接到计算机。有关更多信息,请参阅OpenSSH 8.2 发行说明。
如果您不想在每次使用 SSH 密钥时都重新输入密码,则可以将密钥添加到 SSH 代理,该代理管理您的 SSH 密钥并记住您的密码。
1. 打开git bash
2. 复制以下命令,用你的github邮箱地址代替"your_email@example.com"
$ ssh-keygen -t ed25519 -C "your_email@example.com"
或者:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
3. 生成ssh密钥后,bash会提示你“Enter a file in which to save the key”
这里你可以随意输入文件名,比如仅输入:sshfile
4. 按要求输入ssh 密钥的passphrases
这里可以直接按空格,以后如果需要的话可以更改
working with SSH key passphrases
5. 添加SSH密钥到ssh-agent
打开git bash,输入以下命令启动ssh-agent
# sart the ssh-agent in the background
$ ssh-agent -s
>Agent pid 59566
# 使用现有ssh 密钥的名字替换掉下面命令中的*id_ed25519*
$ ssh-add ~/.ssh/id_ed25519
6. 添加到github–> settings–>SSH and GPG keys
打开git bash
$ clip < ~/.ssh/id_ed25519.pub
# Copies the contents of the id_ed25519.pub file to your clipboard
将执行上述命令后得到的ssh密钥赋值到GitHub中。