hewking's blog
Author: hewking
Labels: blog
Created: 2024-12-29T13:27:07Z
Link and comments: https://github.com/hewking/blog/issues/35
生成和配置 GitLab SSH key 的步骤:
ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub
ssh -T [email protected]
提示:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
报错如下
The authenticity of host 'gitlab.com (*************)' can't be established.
ED25519 key fingerprint is SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com' (ED25519) to the list of known hosts.
[email protected]: Permission denied (publickey).
这个错误表明 SSH 认证失败,通常有以下几个原因:
# 再次确认公钥内容
cat ~/.ssh/id_ed25519.pub
eval “$(ssh-agent -s)”
ssh-add ~/.ssh/id_ed25519
3. 权限问题,检查 SSH 目录权限:
```bash
# SSH 目录权限应为 700
chmod 700 ~/.ssh
# 私钥权限应为 600
chmod 600 ~/.ssh/id_ed25519
# 公钥权限应为 644
chmod 644 ~/.ssh/id_ed25519.pub
# 使用 -v 参数查看详细连接信息
ssh -Tv [email protected]
最常见的原因是第 1、2 点,建议先确认这两项。
报错 git push gitlab main 执行以上命令现在是输入账号密码,如何配置直接使用 sshkey
需要修改仓库的远程 URL,从 HTTPS 改为 SSH 格式:
git remote -v
# 格式: [email protected]:username/repository.git
git remote set-url gitlab [email protected]:your-username/your-repo.git
或者如果是新克隆仓库,直接使用 SSH URL:
git clone [email protected]:your-username/your-repo.git
之后 push/pull 就会使用 SSH key 认证,不需要输入密码了。