1. Ubuntu安装git ssh

git --version
ssh -V

sudo apt update
sudo apt install -y git openssh-client

2. 在 WSL 中生成 SSH Key

ssh-keygen -t ed25519 -C "邮箱"

# 一路回车即可,默认路径是:
# ~/.ssh/id_ed25519
# ~/.ssh/id_ed25519.pub
# 是否设 passphrase?
# 设:更安全(推荐)
# 不设:更省事

3. 启动 ssh-agent 并加载 key

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# 可以把这两行放进 ~/.bashrc 或 ~/.zshrc,避免每次手动加。

4. 把公钥加到 Git 平台

cat ~/.ssh/id_ed25519.pub

# GitHub
# Settings → SSH and GPG keys → New SSH key

# GitLab / Gitee / 自建 Git
# 用户设置 → SSH Keys

5. 验证 SSH 是否通

ssh -T git@github.com
# Hi xxx! You've successfully authenticated...

6. 配置 Git 身份(WSL 内)

git config --global user.name "你的名字"
git config --global user.email "你的邮箱"

# 确认配置
git config --list