[Git] Git秘诀之一Github SSH Key - 刘傲天

in 默认分类 with 0 comment

在GitHub上设置SSH Key

正常情况下你每次push代码都是需要用户名和密码的,这样的话你每次push相对就比较麻烦一些,但是如果你设置了SSH Key之后,你每次push他就会验证这个SSH Key的真伪,如果正确就直接push上去了,不需要你输入你的用户名和密码,这样就非常的方便了。

创建SSH Key

在Linux上创建SSH Key非常的简单

$:ssh-keygen -t rsa -C "liuaotianmsj@gmail.com"

在这里我输入的是我的邮箱地址,你应该更改为你的邮箱地址

Generating public/private rsa key pair.
Enter file in which to save the key (/home/liuaotian/.ssh/id_rsa):回车
Enter passphrase (empty for no passphrase):回车
Enter same passphrase again:回车
Your identification has been saved in /home/liuaotian/.ssh/id_rsa.
Your public key has been saved in /home/liuaotian/.ssh/id_rsa.pub.

你应该能够看到这些内容,连续按三次回车即可

添加SSH Key

刘傲天-github1
点击右上边的settings
刘傲天-github2
进入ssh*那个
刘傲天-github3
刘傲天-github4
上边填上你的这个SSH Key的标记,下边填的内容通过命令获取

$:cat ~/.ssh/id_rsa.pub

将显示的内容粘贴上去就可以了

最后点Add SSH Key就可以了

验证是否成功

ssh -T git@github.com

The authenticity of host 'github.com (13.250.177.223)' can't be established.

Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi lliuaotian! You've successfully authenticated, but GitHub does not provide shell access.
看到这个内容你应该就是成功了。

END

Responses