查询key:
cat ~/.ssh/id_rsa.pub
1、检查是否已经存在ssh key
ls -al ~/.ssh
已经存在会列出目录文件列表,id_rsa.pub或id_dsa.pub
进入第三步,不存在进入第二步
2、生成ssh key
在终端中输入以下命令,其中邮箱填写你的邮箱地址
ssh-keygen -t rsa -b 4096 -C 'your email@example.com'
接下来的步骤中,按回车键:
Enter file in which to save the key (/Users/hony/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
结果看到这个图形,就可以了
+---[RSA 4096]----+
| o . |
|.o + o + |
|o o + o * . |
|.. o.o + = |
|.o.o .+ S |
| + =+ X . |
|.o oEoO B . |
|o.o o+ B o |
|..o+. + . |
+----[SHA256]-----+
3、把ssh key 添加到远程仓库的账号上
1)复制 SSH key 到粘贴板
pbcopy < ~/.ssh/id_rsa.pub
2)登录github或bitbucket等远程仓库添加SSH key即可。
4、添加新密钥ssh key 到ssh-agent
1)确保ssh-agent是可用的,启动ssh-agent服务。
eval "$(ssh-agent -s)"
2)添加新密钥到 ssh-agent
ssh-add ~/.ssh/id_rsa
“id_rsa”是ssh key对应的文件的名字,
如果要使用一个已经存在的key添加到ssh-agent的话,
替换id_rsa名字即可