生成 SSH 密鑰
-
打開終端:
在 Mac 上,你可以按
Command + Space并輸入 "Terminal" 打開終端。 生成 SSH 密鑰: 在終端中,輸入以下命令來生成 SSH 密鑰:
`ssh-keygen -t ed25519 -C "your_email@example.com"`
.
如果你使用的是較舊的系統(tǒng),不支持 ed25519,你可以使用 rsa:
`ssh-keygen -t rsa -b 4096 -C "your_email@example.com"`
將 `"your_email@example.com"` 替換為你在 GitHub 上注冊的郵箱。
-
保存 SSH 密鑰:
- 當提示 “Enter a file in which to save the key” 時,按
Enter使用默認路徑(通常是~/.ssh/id_ed25519或~/.ssh/id_rsa)。 - 當提示輸入密碼短語時,你可以選擇輸入密碼來增加安全性,或者直接按
Enter跳過。
- 當提示 “Enter a file in which to save the key” 時,按
-
添加 SSH 密鑰到 SSH Agent:
在生成密鑰后,運行以下命令來啟動 SSH agent 并添加你的 SSH 密鑰:
`eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519`
.
如果你使用 rsa,命令應為:
`ssh-add ~/.ssh/id_rsa`
2. 將 SSH 公鑰添加到 GitHub
-
復制 SSH 公鑰:
-
使用以下命令復制你的公鑰內(nèi)容到剪貼板:
<pre>
bash
復制代碼
pbcopy < ~/.ssh/id_ed25519.pub</pre>
如果你使用的是
rsa:<pre>
bash
復制代碼
pbcopy < ~/.ssh/id_rsa.pub</pre>
-
-
登錄 GitHub 并添加 SSH 密鑰:
- 打開 GitHub 并登錄你的賬戶。
- 點擊右上角的頭像,然后選擇
Settings。 - 在左側欄中,點擊
SSH and GPG keys。 - 點擊
New SSH key按鈕。 - 給你的密鑰一個標題,然后在
Key字段中粘貼你剛剛復制的公鑰。 - 點擊
Add SSH key按鈕保存。