我使用Git已经有一段时间了,但不断的密码请求开始让我感到很烦。
我使用的是Mac OS X和GitHub,我按照GitHub的设置Git页面的指示设置Git和SSH密钥。
我还将github SSH密钥添加到了我的Mac OS X密钥链中,正如github的SSH密钥密码页面中提到的那样。我的公钥已在Git中注册。
然而,每次我尝试Git拉时,我都必须输入用户名和密码。除了SSH密钥之外,我是否需要为此设置其他东西?
我使用Git已经有一段时间了,但不断的密码请求开始让我感到很烦。
我使用的是Mac OS X和GitHub,我按照GitHub的设置Git页面的指示设置Git和SSH密钥。
我还将github SSH密钥添加到了我的Mac OS X密钥链中,正如github的SSH密钥密码页面中提到的那样。我的公钥已在Git中注册。
然而,每次我尝试Git拉时,我都必须输入用户名和密码。除了SSH密钥之外,我是否需要为此设置其他东西?
当前回答
Windows和GitHub使用SSH推/拉Git指南:Windows Git图解指南
下载并安装PuTTY设置环境变量“GIT_SSH”=“path\to\plink.exe”(在已安装的腻子文件夹中)-非常重要!!!重新启动Windows资源管理器以使环境变量生效(不能仅重新启动命令提示符)运行puttygen.exe生成新密钥,将公钥复制到GitHub站点将此新私钥保存在磁盘上的安全位置(最好不要Dropbox)运行putty.exe并将SSH连接到github.co通过运行“shell:startup”快速进入启动文件夹。通过选美让您的私钥启动Windows。使用语法“path\to\pageage.exe”“path \to\privatkey”在Startup文件夹中创建快捷方式我们不需要在存储库的.git/config中设置“puttykeyfile”设置非常重要的是,使用的是GitHub的“SSH克隆URL”,而不是HTTPS。
其他回答
在Windows Subsystem for Linux(WSL)上,这是我发现的唯一可行的解决方案:
eval `ssh-agent`; ssh-add ~/.ssh/id_rsa
这是ssh代理未在WSL中正确注册的问题。
我认为您可能有错误的Git存储库URL。
打开.git/config并找到[remote“origin”]部分。确保您使用的是SSH:
ssh://git@github.com/username/repo.git
如果单击克隆或下载并选择SSH,您可以在存储库的主页面中看到SSH URL。
而不是https或git:
https://github.com/username/repo.git
git://github.com/username/repo.git
现在,您可以只使用SSH密钥而不是用户名和密码进行验证。
如果Git抱怨已经添加了'origin',请打开.config文件,将[remote origin]后面的url=“…”部分编辑为url=ssh://github/username/repo.git
其他服务也是如此。确保地址如下:protocol://something@网址
例如,Azure DevOps的.git/config:
[remote "origin"]
url = https://mystore@dev.azure.com/mystore/myproject/
fetch = +refs/heads/*:refs/remotes/origin/*
如果您使用https协议,Git将提示您输入密码。如果您使用ssh,它将使用您的私钥进行身份验证,而不是询问密码。
以下是解决此问题的方法:
git远程-v
这将显示来源的url。您将注意到此url中的https。(此处示例)
现在,您必须先删除这个,然后使用ssh添加url
git remote remove origin
git remote add origin git@github.com:PrestaShop/PrestaShop.git
步骤1:检查当前配置
cat .git/config
您将获得:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/path_to_your_git.git
fetch = +refs/heads/*:refs/remotes/origin/*
[user]
name = your_username
email = your_email
[branch "master-staging"]
remote = origin
merge = refs/heads/master-staging
步骤2:删除远程源
git remote rm origin
步骤3:使用用户名和密码添加远程源
git remote add origin https://your_git_username:your_git_password@github.com/path_to_your_git.git
在windows机器中:安装GitHub CLI
choco install gh
然后运行命令:
gh auth login
并遵循说明
您也可以点击此链接:
https://cli.github.com/manual/gh_auth_login