现在做的SSH 配置本质上是在建立你的电脑 ↔ GitHub 之间的可信身份认证关系。简单说告诉 GitHub这台电脑以后执行 Git 操作时证明自己是我不需要每次输入账号密码。一、什么是 SSH 公钥SSH 使用公钥 私钥进行身份认证电脑 ├── 私钥id_ed25519 │ ↓ 保存在本地不要泄露 │ └── 公钥id_ed25519.pub ↓ 上传到 GitHubGitHub 通过公钥识别你的电脑从而允许你进行git push git pull git clone无需每次浏览器登录。二、生成 SSH 密钥打开 PyCharm Terminal 或 PowerShellssh-keygen -t ed25519 -C 你的GitHub邮箱出现Enter file in which to save the key:直接按Enter使用默认路径C:\Users\用户名\.ssh\id_ed25519出现Enter passphrase:直接按Enter不设置密码。再次Enter same passphrase again:继续Enter生成成功Your identification has been saved in C:\Users\wangy\.ssh\id_ed25519 Your public key has been saved in C:\Users\wangy\.ssh\id_ed25519.pub其中文件作用id_ed25519私钥不要分享id_ed25519.pub公钥上传 GitHub三、查看 SSH 公钥执行cat ~/.ssh/id_ed25519.pub输出类似ssh-ed25519 AAxxxxxxxxxI1NTE5AAAAIxxxxxx xxxxxxxxxxxxxxxxxx.com复制整行内容。格式必须完整ssh-ed25519 空格 密钥字符串 邮箱四、添加公钥到 GitHub进入GitHub → Settings → SSH and GPG keys → New SSH key填写TitleWindows-PCKey粘贴刚才复制的ssh-ed25519 AAAAC3...点击Add SSH key五、测试 SSH 连接终端执行ssh -T gitgithub.com第一次可能出现Are you sure you want to continue connecting?输入yes成功Hi username! Youve successfully authenticated, but GitHub does not provide shell access.表示✅ SSH 公钥配置成功六、查看仓库是否使用 SSH查看git remote -vHTTPShttps://github.com/user/project.git改成 SSHgit remote set-url origin gitgithub.com:user/project.git例如git remote set-url origin gitgithub.com:Wangsir2002131/test.git之后git push