首先检查你的电脑是否已有 SSH 密钥:
ls -al ~/.ssh
如果看到 id_rsa 和 id_rsa.pub 文件,说明已有密钥,可跳过生成步骤。
ssh-keygen -t rsa -C "your_email@example.com"
id_rsa(私钥)和 id_rsa.pub(公钥)文件cat ~/.ssh/id_rsa.pub
复制输出的全部内容(以 ssh-rsa 开头,你的邮箱结尾)
ssh -T git@gitee.com
如果看到类似以下欢迎信息,说明配置成功:
Hi YourName! You've successfully authenticated, but GITEE.COM does not provide shell access.
现在你可以使用 SSH 方式克隆仓库,无需每次输入密码:
git clone git@gitee.com:username/repository.git
权限问题:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
多账号配置:
如果需要为不同 Gitee 账号配置不同密钥,可编辑 ~/.ssh/config 文件:
Host gitee.com
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa
连接超时:
检查网络是否可访问 gitee.com,或尝试使用 HTTPS 代理。
通过以上步骤,你就可以实现 Gitee 的 SSH 免密登录了。