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建立成功 ;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Blazor Hybrid适配到HarmonyOS系统
· 支付宝 IoT 设备入门宝典(下)设备经营篇
· 万字调研——AI生成内容检测
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库