一 生成公钥
ssh-keygen -t rsa -C "michelangelo@qq.com"
-t :密钥类型。
-C : 注释。通常用作密钥的名字。
依次按三次回车:默认文件名、无密码。
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/haifeng/.ssh/id_rsa):
Created directory '/Users/haifeng/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/haifeng/.ssh/id_rsa.
Your public key has been saved in /Users/haifeng/.ssh/id_rsa.pub.
The key fingerprint is:
二 查看生成文件
生成两个文件,id_rsa是私钥,id_isa.pub是公钥。
cd ~/.ssh
ls
三 查看公钥内容
cat ~/.ssh/id_rsa.pub
cat命令连接文件并打印到标准输出设备上。cat经常用来显示文件的内容。
四 将公钥添加到GitHub
1 打开个人设置页面
2 点击添加SSH Key按钮
3 输入名称、公钥文本(使用cat ~/.ssh/id_rsa.pub查看)