github添加SSH Key Windows 解决方案

1. 生成 SSH Key

打开终端,执行以下命令:

# 生成新的 SSH Key(替换为你的邮箱)
ssh-keygen -t ed25519 -C "your_email@example.com"

# 或者使用 RSA(兼容性更好)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

2. 设置密钥文件路径

系统会提示:

Enter file in which to save the key (/Users/you/.ssh/id_ed25519):

直接按回车使用默认路径
或输入自定义路径(如 /Users/you/.ssh/github_key)

3. 设置密码(可选)

Enter passphrase (empty for no passphrase):

可以设置密码增加安全性,或直接按回车跳过。

4. 复制公钥 手动添加(无需 ssh-agent)

# 方法1:使用 PowerShell
Get-Content ~\.ssh\id_ed25519.pub | Set-Clipboard

# 方法2:使用 Git Bash
cat ~/.ssh/id_ed25519.pub | clip

5. 添加到 Git 平台(GitHub/GitLab/Gitee

6. 测试连接

# 在 PowerShell 或 Git Bash 中测试
ssh -T git@github.com
Hi tb659! You've successfully authenticated, but GitHub does not provide shell access.