0
点赞
收藏
分享

微信扫一扫

[github]创建SSH密钥,并连接github

蛇发女妖 2023-05-02 阅读 52


一、Windows环境下生成SSH key且连接GitHub

step 1、看看是否存在SSH密钥(keys)

首先,我们需要看看是否看看本机是否存在SSH keys,打开Git Bash,并运行:


$cd ~/.ssh
# 检查你本机用户home目录下是否存在.ssh目录


如果,不存在此目录,则进行第二步操作,否则,你本机已经存在ssh公钥和私钥,可以略过第二步,直接进入第三步操作。

step 2、创建一对新的SSH密钥(keys)

输入如下命令:


$ssh-keygen -t rsa -C "your_email@example.com"
# 这将按照你提供的邮箱地址,创建一对密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]


/c/Users/you/.ssh/github_rsa

接着,根据提示,你需要输入密码和确认密码。相关提示如下:


Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]


输入完成之后,屏幕会显示如下信息:


Your identification has been saved in /c/Users/you/.ssh/id_rsa.
Your public key has been saved in /c/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


step 3、在GitHub账户中添加你的公钥


clip < ~/.ssh/id_rsa.pub


接着:

  1. 登陆GitHub,进入你的Account Settings. 
  2. 在左边菜单,点击”SSH Keys”. 
  3. 点击”Add SSH key”按钮. 
  4. 粘贴你的密钥到key输入框中. 
  5. 点击”Add Key”按钮。 
  6. 再弹出窗口,输入你的GitHub密码,点击确认按钮。
  7. 到此,大功告成了!

step 4、测试

为了确认我们可以通过SSH连接GitHub,我们输入下面命令。输入后,会要求我们提供验证密码,输入之前创建的密码就ok了。


$ssh -T git@github.com


 如果是公司内部的github,则需要输入公司的github域名,如 ssh -T git@github.corp.baidu.com

你可能会看到告警信息,如下:


The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?


不用担心,直接输入yes。

如果看到下面信息,就说明一切完美!


Hi username! You've successfully authenticated, but GitHub does not provide shell access.



mac环境设置请参考: http://www.blogways.net/blog/2013/04/10/generating-ssh-keys-4-github.html


举报

相关推荐

0 条评论