Py学习  »  Git

git初始化配置

取舍🍂 • 4 年前 • 213 次点击  
阅读 3

git初始化配置

如何生成SSH key

SSH key提供了一种与GitHub通信的方式,通过这种方式,能够在不输入密码的情况下,将GitHub作为自己的remote端服务器,进行版本控制

步骤

  • 检查SSH keys是否存在
  • 生成新的ssh key
  • ssh key添加到GitHub中

1. 检查SSH keys是否存在

输入下面的命令,如果有文件id_rsa.pubid_dsa.pub,则直接进入步骤3将SSH key添加到GitHub中,否则进入第二步生成SSH key

ls -al ~/.ssh
复制代码

如下图就表示存在,可以直接跳入第三步:

2. 生成新的ssh key

  1. 第一步:生成public/private rsa key pair 在命令行中输入ssh-keygen -t rsa -C "your_email@example.com"

默认会在相应路径下(/your_home_path)生成id_rsaid_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):
复制代码
  1. 第二步:输入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
复制代码
  1. 第三步:将新生成的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中

用自己喜欢的文本编辑器打开id_rsa.pub文件,里面的信息即为SSH key,将这些信息复制到GitHub的Add SSH key页面即可

不同的操作系统,均有一些命令,直接将SSH key从文件拷贝到粘贴板中,如下:

  • Mac
pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
复制代码
  • Windows
clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
复制代码
  • Linux
sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
复制代码

复制上面的key后粘贴到github new key即可,如下图:

其他

联系

如果大家有兴趣,欢迎关注公众号:_facebook(web技术进阶),查看更多优质文章,欢迎大家加入我的前端交流群:866068198 ,一起交流学习前端技术。博主目前一直在自学Node中,技术有限,如果可以,会尽力给大家提供一些帮助,或是一些学习方法.

  • 公众号
  • 群二维码

福利

有需要刷钻,刷会员,刷腾讯视频会员,涨粉丝等等相关意向的小伙伴们,可以访问作者推荐的超值代刷网站:qq.usword.cn, 也可以扫描下方二维码

最后

If you have some questions after you see this article, you can contact me or you can find some info by clicking these links.

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52981
 
213 次点击