Github笔记 之设置SSH Key密钥

如题所述

第1个回答  2022-06-30
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.

若有不当之处,敬请原谅。
相似回答