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的路径

相关推荐
我命由我1234510 小时前
Git 推送报错:error: src refspec main does not match any
运维·git·gitee·github·运维开发·学习方法·版本控制
阿里嘎多学长11 小时前
2026-09-20 GitHub 热点项目精选
开发语言·程序员·github·代码托管
峰向AI12 小时前
skill-up: [阿里开源] 让 AI Agent Skills 自己进化的评估工具
github
熊明才15 小时前
WSL2 网络突然瘫痪(Network is unreachable / 没有 eth0)最短修复指南(2026年9月20日亲测可用)
linux·windows·wsl2
子林super16 小时前
顺序表用Python3定义与增删改查
github
子林super16 小时前
Python非空判断与类型检查写法
github
子林super16 小时前
Python list与array关键区别及使用场景
github
子林super16 小时前
Python中None与null的区别
github
u13013018 小时前
GitHub 热榜项目:周榜(2026-09-20)
人工智能·github
u13013019 小时前
GitHub 热榜项目:日榜(2026-09-20)
人工智能·github