linux生成SSH key
·
如何生成SSH key
SSH key提供了一种与GitHub通信的方式,通过这种方式,能够在不输入密码的情况下,将GitHub作为自己的remote端服务器,进行版本控制
步骤
- 检查SSH keys是否存在
- 生成新的ssh key
- 将ssh key添加到GitHub中
1. 检查SSH keys是否存在
输入下面的命令,如果有文件id_rsa.pub
或 id_dsa.pub
,则直接进入步骤3将SSH key添加到GitHub中,否则进入第二步生成SSH key
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
2. 生成新的ssh key
第一步:生成public/private rsa key pair
在命令行中输入ssh-keygen -t rsa -C "your_email@example.com"
默认会在相应路径下(/your_home_path)生成id_rsa
和id_rsa.pub
两个文件,如下面代码所示
ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):
第二步:输入passphrase(本步骤可以跳过)
设置passphrase后,进行版本控制时,每次与GitHub通信都会要求输入passphrase,以避免某些“失误”
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
sample result:
Your identification has been saved in /your_home_path/.ssh/id_rsa.
Your public key has been saved in /your_home_path/.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
第三步:将新生成的key添加到ssh-agent中:
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
ssh-add ~/.ssh/id_rsa
3. 将ssh key添加到GitHub中
本文首载于Gevin's blog
文/Gevin(简书作者)
原文链接:http://www.jianshu.com/p/31cbbbc5f9fa/
原文链接:http://www.jianshu.com/p/31cbbbc5f9fa/
更多推荐
已为社区贡献5条内容
所有评论(0)