github SSH连接(windows)

以下命令均在本地电脑的 Git Bash (本地安装git时,顺带安装) 中执行

准备 SSH 密钥

  • 已有 ssh 密钥的可直接使用

  • 忘记是否有 ssh 密钥,可以通过ls -al ~/.ssh查看现有的 ssh 密钥对,提示:如果收到.ssh不存在,则默认位置中没有 ssh 密钥,需生成新 ssh 密钥

  • 生成新 ssh 密钥
    ssh-keygen -t ed25519 -C "youe_email@example.com"里面使用的电子邮件替换成 github 电子邮件地址

    注意:如果系统不支持 ed25519 算法,请使用下面这个:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    > Enter file in which to save the key: [Press enter], 按 Enter 键接受默认文件位置(c:\User\alan.ssh\id_ALGORITHM)注意:如果以前创建了 ssh 密钥,需要自定义命名的 ssh 密钥,修改默认位置的id_ALGORITHM

    根据提示,输入安全密码:

    > Enter passphrase (empty for no passphrase): [Type a passphrase]

    > Enter same passphrase again: [Type passphrase again]

    会得到如下两个文件:

添加 SSH 密钥

登录 github 选择 设置

选择 SSH and GPG keys, 然后选择 New SSH key

输入自己的备注Title, 然后将本地 ssh 的公钥复制到Key中即可生成

测试 SSH 连接

输入命令ssh -T git@github.com测试,你会看到类似以下类似的返回:

>The authentictiy of host 'github.com (IP ADDRESS)' can't be established.

>ED25519 key fingerprint is SHA256:+DiT3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.

>Are you sure you want to continue connecting (yes/no)?

输入yes, 返回:

> Hi USERNAME! You've successfully authenticated, but GitHub does not

> provide shell access

则表示通过,若收到"权限被拒绝",请参阅 错误:权限被拒绝(公钥)

若一直返回连接超时,可尝试使用代理访问

配置 SSH 代理

在默认存放 ssh 密钥对的地方[c:\User\alan.ssh],创建config文件,注意文件没有后缀,如图:

用记事本打开config文件,写入:

复制代码
ProxyCommand "C:\Program Files\Git\mingw64\bin\connect" -S 127.0.0.1:1024 -a none %h %p

替换你的端口号和connect.exe的路径

相关推荐
我是哪吒1 小时前
分布式微服务系统架构第170集:Kafka消费者并发-多节点消费-可扩展性
后端·面试·github
GitLqr3 小时前
AI洞察 | Hunyuan-MT 翻译模型开源,谷歌终端嵌入模型登场
github·ai编程·gemini
三无少女指南4 小时前
WSL2环境下因服务器重装引发的SSH连接问题排查记录
运维·服务器·ssh
杨杨杨大侠4 小时前
第2章:设计核心接口和事件模型
java·github·eventbus
杨杨杨大侠4 小时前
第1章:事件驱动框架基础概念
java·github·eventbus
一点都不方女士6 小时前
《无畏契约》游戏报错“缺少DirectX”?5种解决方案(附DirectX修复工具)
windows·游戏·microsoft·动态链接库·directx·运行库
0wioiw07 小时前
Python基础(①⑧Queue)
windows·python
寒水馨8 小时前
Windows 11 手动下载安装配置 uv、配置国内源
windows·python·国内源·uv·windows11
Mintind8 小时前
windows找不到gpedit.msc(本地组策略编辑器)
windows