生成公鑰
打開命令行終端輸入ssh-keygen -t rsa -C “username@example.com”,接下來點(diǎn)擊enter鍵即可(也可以輸入密碼)。
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] // 推薦使用默認(rèn)地址
Enter passphrase (empty for no passphrase):
之后會(huì)提示想要存放公鑰的文件位置及密碼;文件位置不填的話就會(huì)默認(rèn)為 /Users/you/.ssh/id_rsa
成功之后
Your identification has been saved in /Users/you/.ssh/id_rsa.
# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
本地打開 id_rsa.pub 文件,其內(nèi)容就是生成的公鑰內(nèi)容。
管理多個(gè)公鑰
如果需要使用多個(gè)賬戶建議生成多個(gè)公鑰,可以在.ssh/config文件中加上下邊一段
Host git.coding.net
User xxxx@email.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/coding_rsa // 生成的非默認(rèn)地址的公鑰存放點(diǎn)