Github笔记 之设置SSH Key密钥

Github笔记 之设置SSH Key密钥,第1张

Github 链接已有仓库时的认证,是通过使用SSH 的公开密钥认证的。

首先,创建SSH Key ,语法:

$ ssh-keygen -t rsa -C "content neirong"

-t :密钥的类型 

-C : 用于识别密钥的注释

-C 一般大家都写的是Email邮箱

以下小者测试的例子:

$ ssh-keygen -t rsa -C "add wm public ssh"

Generating public/private rsa key pair.

Enter file in which to save the key (/c/Users/xx/.ssh/id_rsa):

Created directory '/c/Users/\351\207\212\345\246\202\347\247\230/.ssh'.

下面是要输入的密码:

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /c/Users/xx/.ssh/id_rsa

Your public key has been saved in /c/Users/xx/.ssh/id_rsa.pub

The key fingerprint is:

SHA256:NGpvF0aaCWM5LsyZz6uTsqPI1UxEiLI9xCOEXdcIDX4 add wm public ssh

The key's randomart image is:

+---[RSA 3072]----+

|o+..==.o        |

|+.=o..o..        |

|.= ...E o .      |

|. oo.* * *      |

|  .*.+ S o      |

|    += . . .    |

|  . +o o .      |

|o + o  o .      |

|oo.+.o.          |

+----[SHA256]-----+

小者设置的密码是空。

id_rsa 文件是私有密钥,id_rsa.pub是公开密钥。

查看公开密钥的方法:

$ cat ~/.ssh/id_rsa.pub

把本地设置的公开密钥添加至GitHub中。

现在验证一下用手中的私有密钥与GitHub进行认证和通信了。

语法:

$ ssh -T [email protected]

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

RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.

This key is not known by any other names

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes (这里输入yes)

出现以下说明成功通信:

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

若有不当之处,敬请原谅。

git官网  按照电脑 *** 作系统一直回车下去安装就行

git安装完成后,需要手动配置ssh密钥

配置github的ssh密钥:

1.在桌面上右键,打开git bash查看电脑上是否已经存在SSH密钥:

输入 cd ~/.ssh

2.创建新的ssh key:

输入 ssh-keygen -t rsa -C "[email protected]

执行这条命令会如上图提示文件保存路径,可以直接按Enter,

然后提示输入 passphrase(密码),输入两次(可以不输直接两次Enter),

然后会在 .ssh 目录生产两个文件:id_rsa和id_rsa.pub

3.用记事本打开.ssh目录下的id_rsa.pub文件,复制里面的内容,或者直接执行命令查看:

$ cat ~/.ssh/id_rsa.pub

4、复制ssh key到github:

On the GitHub site Click “Settings” > Click “SSH and GPG Keys” > Click “New SSH key”

打开github网站,点击右上角扳手图标,然后点击左边菜单的 ssh key, 然后右边页面的 add ssh key,将复制的内容粘贴到github的key中,title可填不填,填好保存即可。

配置user.name和user.email

$ git config --global user.name 'your_name'

$ git config --global user.email '[email protected]'

$ git config --global --list查看user信息设置好的user信息

$ git config --list 查看自己的git信息

$ git config --local  local只针对某个仓库有效

$ git config --global global对当前用户所有仓库有效

$ git config --system 对系统所有登陆的用户有效

$ git config --list --local 

$ git config --list --global 

$ git config --list --system 


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/bake/11515585.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存