添加SSH密钥后,Github上的身份验证失败

Ama*_*pta 11 ssh github

我致命:当我尝试将代码推送到我的仓库时,验证失败.我也在我的github帐户上添加了公钥.当我这样做时: ssh -i git@github.com
我明白了 Hi amangupta052! You've successfully authenticated, but GitHub does not provide shell access.

有人可以帮忙吗?谢谢

Von*_*onC 28

这取决于您使用的远程URL.

如果git remote -v返回:

https://github.com/username/reponame
Run Code Online (Sandbox Code Playgroud)

然后你的ssh设置无关紧要.但这会奏效:

ssh://git@github.com:username/reponame
Run Code Online (Sandbox Code Playgroud)

另一个原因与您的私钥相关联:如果它是密码短语保护,其中包含特殊字符,通常效果不佳.
请参阅此处了解其他ssh失败原因.


要替换您的远程命名origin,请使用git remote命令:

git remote set-url origin ssh://git@github.com:username/reponame
Run Code Online (Sandbox Code Playgroud)

(如关于更改rmeote urlGitHub帮助页面中所述)

如果你看到::

ssh: Could not resolve hostname github.com:amangupta052: 
     Name or service not known 
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)

尝试使用非scp ssh语法:

git remote set-url origin ssh://git@github.com/username/reponame
Run Code Online (Sandbox Code Playgroud)

(注意' /'而不是' :'之后github.com)

也许这会有效,正如在这篇博文中评论的那样:

git remote set-url origin git@github.com:username/reponame
Run Code Online (Sandbox Code Playgroud)

(类似scp的语法,但没有ssh://前缀)

正如我在这里提到的,scp语法通常意味着~/.ssh/config文件可以正常工作.