步驟一:查看已存在的 SSH 密鑰
ED25519 算法
cat ~/.ssh/id_ed25519.pub
RSA 算法
cat ~/.ssh/id_rsa.pub
如果返回一長串以 ssh-ed25519 或 ssh-rsa 開頭的字符串, 說明已存在本地公鑰
步驟二:生成 SSH 密鑰
若步驟一未返回指定內(nèi)容字符串准颓,表示本地暫無可用 SSH 密鑰,需要生成新的 SSH 密鑰棺妓,請按如下步驟操作:
輸入密鑰算法類型和可選的注釋怜跑。
注釋會出現(xiàn)在.pub文件中样勃,一般可使用郵箱作為注釋內(nèi)容。
- 基于ED25519算法性芬,生成密鑰對命令如下:
ssh-keygen -t ed25519 -C "<注釋內(nèi)容>"
- 基于RSA算法峡眶,生成密鑰對命令如下:
ssh-keygen -t rsa -C "<注釋內(nèi)容>"
3.點擊回車,選擇 SSH 密鑰生成路徑植锉。
- 以 ED25519 算法為例辫樱,默認路徑如下:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
密鑰默認生成路徑:/home/user/.ssh/id_ed25519,公鑰與之對應為:/home/user/.ssh/id_ed25519.pub汽煮。
- 以 RSA 算法為例搏熄,默認路徑如下:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
- 設置一個密鑰口令。
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
口令默認為空暇赤,你可以選擇使用口令保護私鑰文件心例。如果你不想在每次使用 SSH 協(xié)議訪問倉庫時,都要輸入用于保護私鑰文件的口令鞋囊,可以在創(chuàng)建密鑰時止后,輸入空口令。
5溜腐、點擊回車译株,完成密鑰對創(chuàng)建。
打開ssh所在文件
open ~/.ssh
git 使用出現(xiàn)Permission denied (publickey). fatal: Could not read from remote repository.
解決方案:https://blog.csdn.net/YanceChen2013/article/details/82218356