0


如何在Github上配置ssh key的密钥

Step0 : 解释说明

git使用SSH配置, 初始需要以下三个步骤

  1. 使用秘钥生成工具生成rsa秘钥和公钥
  2. 将rsa公钥添加到代码托管平台
  3. 将rsa秘钥添加到ssh-agent中,为ssh client指定使用的秘钥文件

Step 1: 核验本地主机是否已经存在ssh密钥。(若id_rsa和id_rsa.pub文件存在,说明已经存在SSH key密钥,反之,需要生成新密钥)

Maxwell Pan@MaxwellPan MINGW64 ~
$ cd ~/.ssh

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ls
known_hosts

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh

Step 2:生成ssh key

如果不存在ssh key,使用如下命令生成

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Maxwell Pan/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa
Your public key has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:QqppfBW5oA8VAGjWSTouObN23WwhnVowrLbPGLreok4 [email protected]
The key's randomart image is:
+---[RSA 3072]----+
|o.+oo            |
|.o.o.. .         |
|oo  o++          |
|...o.++o.        |
|=.oo..+=S        |
|.=.=o.*..        |
|.E=+oo +         |
|oo+.= .          |
|==oo o           |
+----[SHA256]-----+

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ls
id_rsa  id_rsa.pub  known_hosts

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh

生成完以后再用第二步命令,查看ssh key

Step3:获取ssh key公钥内容(id_rsa.pub)

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ls
id_rsa  id_rsa.pub  known_hosts

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFWXsAPl4sGCgRjTSVOZlxfv2ZWYBteE0gYdmN6A8teeUkh6WCsbqyVtUUNkaaUC9Zpn0xUb8hpMr9Cbhiyy90D2mIuxK37RQWi4mz5PSGIXZ/tNQ/n8oFNrhmAx7ljWmFxvmMB4CVIUCujpYunj6P8vBZaIrR5+Rakec8gjxxxxxxxxxxxxxxxxxGllKPpuVa9f4KjRet0BRXg4oiXE8DB6bODsAjSnBrYlf3Cj3EyhQyA07qygQLEzUItDRMNfLT5UpYTjBk/RqFbB9KpGTtkH9B++lLC6nosN1dwLugEdW05P+SGfay3xlFmc7+f/lgP3xxxxxxxxxxxxxxxxxxxxx80u9mA2RNDz1gqji1sL6K0IdbmqJ7vOi/xBfPs3kswVZxoDiWr8Bh4/xYRYm53rORPLWvMN+AQlCLVq9GlYb2y2mN37PU5qUjs3INzPE9TV1F4EhMl2E5DQhHcbMmILwyqe9+8= [email protected]

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh

复制cat 的内容到Github账号上去 设置密钥。首先点击头像下的setting , 找到SSH and GPG keys这个栏位。点击 New SSH key,将上面cat出来的内容添加到New SSH key,并取个名字。

Step 4 : 验证 配置密钥是否成功。

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ssh -T [email protected]
Hi psmaxwell! You've successfully authenticated, but GitHub does not provide shell access.

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$

设置成功后,即可不需要账号密码clone和push代码

以下为全过程:

Maxwell Pan@MaxwellPan MINGW64 ~
$ cd ~/.ssh

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ls
known_hosts

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Maxwell Pan/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa
Your public key has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:QqppfBW5oA8VAGjWSTouObN23WwhnVowrLbPGLreok4 [email protected]
The key's randomart image is:
+---[RSA 3072]----+
|o.+oo            |
|.o.o.. .         |
|oo  o++          |
|...o.++o.        |
|=.oo..+=S        |
|.=.=o.*..        |
|.E=+oo +         |
|oo+.= .          |
|==oo o           |
+----[SHA256]-----+

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ls
id_rsa  id_rsa.pub  known_hosts

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFWXsAPl4sGCgRjTSVOZlxfv2ZWYBteE0gYdmN6A8teeUkh6WCsbqyVtUUNkaaUC9Zpn0xUb8hpMr9Cbhiyy90D2mIuxK37RQWi4mz5PSGIXZ/tNQ/n8oFNrhmAx7ljWmFxvmMB4CVIUCujpYunj6P8vBZaIrR5+Rakec8gjvxxxxxxxxxxxxaw6YoE1qrGllKPpuVa9f4KjRet0BRXg4oiXE8DB6bODsAjSnBrYlf3Cj3EyhQyA0xxxxxxxxxk/RqFbB9KpGTtkH9B++lLC6nosN1dwLxxxxxxxxxFmc7+f/lgP3bTb9egBjTpYqRC48fwOtYqbmP2HN0wX+9T0c4+9X80u9mA2RNDz1gqji1sL6K0IdbmqJ7vOi/xBfPs3kswVZxoDiWr8Bh4/xYRYm53rORPLWvMN+AQlCLVq9GlYb2y2mN37PU5qUjs3INzPE9TV1F4EhMl2E5DQhHcbMmILwyqe9+8= [email protected]

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$ ssh -T [email protected]
Hi psmaxwell! You've successfully authenticated, but GitHub does not provide shell access.

Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
$
标签: git github ssh

本文转载自: https://blog.csdn.net/u011868279/article/details/129070735
版权归原作者 DB架构 所有, 如有侵权,请联系我们删除。

“如何在Github上配置ssh key的密钥”的评论:

还没有评论