git clone 报错 fatal: Authentication failed for https://github.com
使用git clone拉取代码的时候报错 fatal: Authentication failed for https://github.com
。
推荐使用 SSH 方式避免认证问题:
检查是否已有 SSH 密钥:
bash
ls ~/.ssh
如果没有,生成新的密钥:
bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
按提示保存密钥文件并设置密码。
添加公钥到 GitHub:
复制公钥:
bash
cat ~/.ssh/id_rsa.pub
登录 GitHub,进入 Settings -> SSH and GPG keys -> New SSH Key,粘贴公钥。
测试连接:
bash
ssh -T git@github.com
使用 SSH 克隆仓库:
bash
git clone git@github.com:<username>/<repo>.git
bash
git remote set-url origin git@github.com:wanggch/md.git