流浪のwolf

卷帝

导航

ssh建立github连接 基于ssh密钥

1. 建立公钥和私钥

ps:公钥放在github上面的,私钥放在自己本地电脑 ;

先生成密钥:打开 gitbash 输入命令:

ssh-keygen -t rsa -b 4096 -C "zhulongxu2022@163.com"

中间会让你输入东西不用管,直接一直回车 ;

结果:

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/zhulo/.ssh/id_rsa):
Created directory '/c/Users/zhulo/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/zhulo/.ssh/id_rsa
Your public key has been saved in /c/Users/zhulo/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:zrhuxX/87PmZODzZq1lGIn7TTq1Fqzh0v4IlcAscftI zhulongxu2022@163.com
The key's randomart image is:
+---[RSA 4096]----+
|                 |
|         .       |
|        o o      |
|         * E     |
|       .S *... ..|
|       +o .+.o+.o|
|      ..o..o*o+*o|
|      ..  .o=BX*o|
|     oo    o.B@B+|
+----[SHA256]-----+

有如上代码表示成功;

结果就是生成了密钥并保存在  C:\Users\zhulo\.ssh 里面 ;

 

2. 将SSH密钥添加到ssh-agent

输入 eval 回车 

输入 ssh-agent -s 回车 

 

 3. 把ssh添加到账户

输入 ssh-agent bash 

输入 ssh-add ~/.ssh/id_rsa 

如下结果出现则说明成功 ;

 

 4. 把公钥复制到github上面 

使用命令 cat ~/.ssh/id_rsa.pub 

 

 把这段文字复制到github的新增密钥上面保存即可 ;

终端输入:ssh -T git@github.com 

显示:

The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

选择  yes 回车 显示如下;

Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Hi xxxxxx You've successfully authenticated, but GitHub does not provide shell access.

ps:如果 xxxxx 如果是你的 github 账号名说明ssh建立成功 ;

 

posted on 2023-02-10 09:33  流浪のwolf  阅读(76)  评论(0编辑  收藏  举报