gitlab配置git的ssh秘钥
1. 检查现有 SSH 密钥
ls -al ~/.ssh如果看到类似以下文件,说明已有密钥:
id_rsa和id_rsa.pub(RSA 密钥)id_ed25519和id_ed25519.pub(Ed25519 密钥)
2. 生成新的 SSH 密钥
方法一:使用 Ed25519 算法(推荐)
ssh-keygen -t ed25519 -C "your_email@example.com"方法二:使用 RSA 算法
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"3. 密钥生成过程详解
运行命令后,会提示以下信息:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/your_username/.ssh/id_ed25519):密钥保存路径
直接回车:使用默认路径
/home/your_username/.ssh/id_ed25519自定义路径:输入其他路径
设置密码(可选)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:Windows 用户名包含中文字符,导致路径创建失败
方案一:指定自定义路径(推荐)
# 指定一个简单的路径来保存密钥
ssh-keygen -t ed25519 -C "1097958820@qq.com" -f /e/ssh_keys/id_ed25519方案二:在 Git Bash 中创建目录
# 先创建 .ssh 目录
mkdir -p ~/.ssh# 然后生成密钥
ssh-keygen -t ed25519 -C "1097958820@qq.com"方案三:使用绝对路径
# 使用绝对路径生成密钥
ssh-keygen -t ed25519 -C "1097958820@qq.com" -f /c/Users/Public/.ssh/id_ed25519查看公钥
# 显示公钥内容(复制这个添加到 Git 服务)
cat /e/work/git-ssh/id_ed25519.pub
将sshkey填写到git仓库的用户配置界面


添加成功之后即可正常拉取更新代码了-使用ssh拉取

