gitlab - GitLab 在添加 SSH 密钥后要求输入密码
问题描述
亲爱的 StackOverflow 社区,
我按照这个( https://gitlab.com/help/ssh/README)指令创建了 ssh-keys 。我将 ED25519 SSH 密钥对添加到网页上的 GitLab 配置文件中,如果我这样做了,ssh -T git@gitlab.com
我确实获得了消息Welcome to GitLab, @username!
,到目前为止它似乎工作。
git push
但是,我想git pull
从我的本地存储库到 GitLab,而无需每次都输入我的密码。据我了解 SSH 密钥,这应该正是他们所做的事情,对吧?
编辑:
我的.ssh/config
包含:
Host machine
User username
HostName machine.webside.com
.gitconfig
包含:
[user]
name = John Doe
email = john.doe@email.com
并且.git/config
包含:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://gitlab.com/johndoe/projectname.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "branch1"]
remote = origin
merge = refs/heads/branch1
[branch "branch2"]
remote = origin
merge = refs/heads/branch2
解决方案
您.git/config
表明您的存储库是通过 HTTPS 访问的,因此使用用户名和密码身份验证。
如果要切换到 ssh,除了添加 SSH 密钥外,还必须更改本地 GIT 配置。
GitHub 有一个关于将 GIT 远程 URL 从 HTTPS 更改为 SSH 的非常详细的教程:https ://help.github.com/en/articles/changeing-a-remotes-url#switching-remote-urls-from- https-to-ssh
那里描述的步骤也适用于 GitLab,除了您的远程 URL 将类似于git@gitlab.com:<repo-url.git>
而不是git@github.com:<repo-url>.git
或多或少,您只需要使用git remote set-url origin
.
推荐阅读
- c# - 如何使用 C# 的管理员权限启动 PowerShell?
- javascript - 在 Gatsby 中查询子节点字段
- python - 如何在我的 tkinter 窗口上显示我的控制台日志?
- typescript - 如何从构造函数继承类变量类型?
- ios - 如何自动显示警报 iOS
- arrays - 将数组拆分为列表
- node.js - Mern Stack App - 为什么“编辑”功能不起作用?
- node.js - 运行 gulp 任务时如何解决“不推荐使用 MakeCallback 中的域属性”警告?
- python - TypeError: strptime() argument 1 must be str, not float 不明白为什么会这样
- docker - 在 WSL2 Ubuntu 18 LTS 上运行 docker 的问题