亲爱的stackoverflow社区,
我在此之后创建了ssh-keys(https://gitlab.com/help/ssh/readme(指令。我在网页上的gitlab配置文件中添加了ED25519 SSH密钥对,如果我做ssh -T git@gitlab.com
,我确实会获取消息Welcome to GitLab, @username!
,因此它似乎可以正常工作。
但是,我想从本地存储库到gitlab git push
和 git pull
,而无需每次输入密码。据我了解,SSH-Keys应该正是他们所做的事情,对吗?
编辑:
我的.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/changing-a-remotes-url#switching-remote-urmote-urls - 从https到ssh
所述的步骤也适用于GitLab,除了您的远程URL将是git@gitlab.com:<repo-url.git>
而不是git@github.com:<repo-url>.git
或多或少,您只需要使用git remote set-url origin
。