用SSH连接GitHub

1、关于SSH:

使用SSH协议, 你可以连接并认证远程服务器和服务。有了SSH Keys,连接到GitHub就不用每次访问

都提供用户名和密码。

2、检查现有的SSH Keys

在你生成一个SSH Key前,你可以检查你是否已经有了一些SSH Keys。

(1)Open Terminal

(2)输入 ls -al ~/.ssh 是否存在一些已有的SSH Keys

(3)Check the directory listing to see if you already have a public SSH key.

默认,public keys的文件名是如下之一:

  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
  • id_rsa.pub

  • If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.

  • If you see an existing public and private key pair listed (for example id_rsa.pub and id_rsa) that you would like to use to connect to GitHub, you can add your SSH key to the ssh-agent.

3、生成一个新的SSH Key,并将其添加到ssh-agent

如果不想在每次使用SSH Key时都输入密码,你可以将Key添加到SSH agent,它会管理你的

SSH key并记住密码。

3.1、生成一个SSH Key

(1)打开终端

(2)执行 ssh-keygen -t rsa -b 4096 -C [email protected]

(3)此时会提示你:"Enter a file in which to save the key,"直接回车就行。

3.2、将生成的key添加到ssh agent中

(1)后台启动ssh-agent:eval "$(ssh-agent -s)"

(2)将你的SSH私有key添加到ssh-agent:ssh-add ~/.ssh/id_rsa

4、将Key添加到Github账号:

直接按此文章去做吧:

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

5、测试连接:

https://help.github.com/articles/testing-your-ssh-connection/#platform-linux

这是我的成功连接的输出:

[fanjg@localhost ~]$ ssh -T [email protected]
Hi gitFanjg! You've successfully authenticated, but GitHub does not provide shell access.

猜你喜欢

转载自zsjg13.iteye.com/blog/2399045
今日推荐