简体   繁体   English

ssh -T git@github.com:你已经成功认证 | sudo git pull:权限被拒绝(公钥)

[英]ssh -T git@github.com: You've successfully authenticated | sudo git pull: Permission denied (publickey)

I know this is a replica of the question Git push permission denied (publickey) but successfully authenticated我知道这是问题Git 推送权限被拒绝(公钥)但已成功验证的副本

But the real issue is not solved.但真正的问题并没有解决。

I have been using https connection for the past year on my prod Linux server and as you all know git removed the HTTPS ability to pull and push. I have been using https connection for the past year on my prod Linux server and as you all know git removed the HTTPS ability to pull and push. Now it is all done though the SSH.现在这一切都通过 SSH 完成。

So i went through github guide how to set up the ssh.所以我浏览了 github 指南如何设置 ssh。 Generating ssh keys with "ssh-keygen -t ed25519 -C "your_email@example.com"" Adding it to the ssh agent and all of that done correctly 100 times checked through.使用 "ssh-keygen -t ed25519 -C "your_email@example.com"" 生成 ssh 密钥,将其添加到 ssh 代理,所有这些都正确完成了 100 次检查。

So this is what I have:所以这就是我所拥有的:

ssh-add -l

or或者

ssh-add -l -E sha256

returns me this:给我这个:

256 SHA256 BLAH BLAH BLAH (which is matching to my github account key)

another command另一个命令

ssh -vT git@github.com

returns big list (dont think there is a need to show it all) of the commands ran through but as the outcome it connects and returns my username:返回运行的命令的大列表(不认为有必要全部显示),但结果它连接并返回我的用户名:

debug1: Reading configuration data /home/[userName]/.ssh/config
debug1: /home/[userName]/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [140.82.121.4] port 22.
debug1: Connection established.
debug1: identity file /home/[userName]/.ssh/id_ed25519 type 3
debug1: key_load_public: No such file or directory
debug1: identity file /home/[userName]/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version babeld-d410d4f8
debug1: no match: babeld-d410d4f8
debug1: Authenticating to github.com:22 as 'git'
...........
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([140.82.121.4]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = ru_RU.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi GitHubUserName! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2012, received 2388 bytes, in 0.2 seconds
Bytes per second: sent 8477.3, received 10061.5
debug1: Exit status 1

another one:另一个:

ssh -T git@github.com

return this:返回这个:

Hi GitHubUserName! You've successfully authenticated, but GitHub does not provide shell access.

I know many of you going to think i might use HTTPS remote url but no.我知道你们中的许多人会认为我可能会使用 HTTPS 远程 url 但没有。 It is ssh remote.它是 ssh 遥控器。 And also to another question that was asked to this replica question: My project is existed one, and on my prod server i have only been pulling for the past year.还有另一个被问到这个副本问题的问题:我的项目已经存在,并且在我的产品服务器上,我只是在过去一年中一直在拉动。 So the project is existing in my repo, I only need to pull.所以该项目存在于我的仓库中,我只需要拉取即可。 With existing branch too (JUST TO MAKE SURE IF SOMEONE tries to say something FUNNY:D )也有现有的分支(只是为了确保如果有人试图说一些有趣的话:D)

git remote -v

returns:返回:

origin  git@github.com:[myUserName]/[myRepo].git (fetch)
origin  git@github.com:[myUserName]/[myRepo].git (push)

another one to make sure i have the.ssh/config file which previously i didnt have it.另一个以确保我拥有以前没有的 .ssh/config 文件。 But also tried to create it and set it up just incase it will fix my issue (but it didnt resolve the permission issue) so the content of the config file is:但也尝试创建并设置它以防万一它会解决我的问题(但它没有解决权限问题)所以配置文件的内容是:

Host github.com
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_ed25519
TCPKeepAlive yes
IdentitiesOnly yes

The ssh/id_ed25519 is the default ssh generation name by the Github SSH guide. ssh/id_ed25519 是 Github SSH 指南的默认 ssh 代名称。 Only thin I have added the Passphrase.我只添加了密码短语。 I was thinking that the issue is in the Passphrase, but i was wrong.我以为问题出在密码短语中,但我错了。 After i deleted the keys and created ssh key again with the default settings without Passphrase gave me the same result.在我删除密钥并使用没有密码的默认设置再次创建 ssh 密钥后,我得到了相同的结果。 In fact when I had Passphrase set, and running the pull command it never asked me for the Passphrase to be entered, it was throwing the Permission connection error straight away, which i found very strange on this part.事实上,当我设置密码短语并运行拉取命令时,它从未要求我输入密码短语,它立即抛出了权限连接错误,我觉得这部分很奇怪。

So when I run command所以当我运行命令时

sudo git pull

even if I try to do it with origin and branch name still the same result:即使我尝试使用原点和分支名称进行操作,结果仍然相同:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Please guys help me out.请大家帮帮我。 I am stacked on this for over 5 hours already.我已经在这上面堆了 5 个多小时了。 Tried every single stackoverflow & github suggestion.尝试了每一个 stackoverflow 和 github 建议。 No idea why it doesnt work for prod web server.不知道为什么它不适用于产品 web 服务器。

On my local I use only ssh git connection and it is working like a clock.在我的本地,我只使用 ssh git 连接,它像时钟一样工作。 The same setups.相同的设置。

At some point I think maybe it is some admin linux restrictions or something like it.在某些时候,我认为可能是一些管理员 linux 限制或类似的东西。 But not sure.但不确定。

Please suggest me something.请给我一些建议。 In advance, big thanks for your help!提前,非常感谢您的帮助!

I prefer, when using a ~/.ssh/config entry, to:在使用 ~/.ssh/config 条目时,我更喜欢:

  • name that entry with a distinct name (like 'gh'), as opposed to github.com, in order be sure when I use a ssh/config -defined URL (and not a regular SSH URL based on github.com ) name that entry with a distinct name (like 'gh'), as opposed to github.com, in order be sure when I use a ssh/config -defined URL (and not a regular SSH URL based on github.com )
  • include (as you did) the User git in it, in order to not have to repeat it在其中包含(如您所做的) User git ,以便不必重复

So:所以:

Host gh
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_ed25519
TCPKeepAlive yes
IdentitiesOnly yes

That way, your remote becomes:这样,你的遥控器就变成了:

cd /path/to/repo
git remote set-url origin gh:[myUserName]/[myRepo].git

Not need for git@ .不需要git@

As commented, you then need to git pull using the same account (instead of /root ) if you want to actually use said config.如评论所述,如果您想实际使用所述配置,则需要使用相同的帐户(而不是/root )进行git pull

For anyone who experience the same issue.对于任何遇到同样问题的人。 The solution is: @Stephen Newell and @fredrik gave me the idea what could be actually wrong with my environment instead of actual GIT issue.解决方案是:@Stephen Newell 和@fredrik 让我知道我的环境实际上可能出了什么问题,而不是实际的 GIT 问题。 So technically when in /var/www/ and youre doing any actions that mutate the files in any directory /var you will get permission issue.因此,从技术上讲,当您在 /var/www/ 中并且您正在执行任何改变任何目录 /var 中文件的操作时,您将遇到权限问题。 And you require run the commands with sudo.您需要使用 sudo 运行命令。 So the fact that I had the key generated in the ~/.ssh folder.因此,我在 ~/.ssh 文件夹中生成了密钥。 When you run the sudo command this ~/.ssh is completely different to the one when in side the "sudo su".当您运行 sudo 命令时,此 ~/.ssh 与“sudo su”中的完全不同。 See it yourself.自己看吧。 Check in normal dir ~/.ssh is different to the one when you log in into "sudo su".检查正常目录 ~/.ssh 与登录“sudo su”时的目录不同。 If you see that your key is missing inside the "sudo su" and then in dir "~/.ssh" that would be the reason why you get the permission error, coz you do not have the key inside the SUDO.如果您发现您的密钥在“sudo su”中丢失,然后在目录“~/.ssh”中丢失,这将是您收到权限错误的原因,因为您在 SUDO 中没有密钥。

Solution is simple: login into "sudo su" and then generate the ssh key.解决方案很简单:登录“sudo su”,然后生成 ssh 密钥。 After copy paste that key in the git as the github guide tells you.在 git 中复制粘贴该密钥后,github 指南告诉您。

I hope it will solve the issue for you.我希望它能为你解决问题。

Thanks for reading it.感谢您阅读。 Happy hacking:D快乐的黑客:D

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取ssh git@github.com:权限被拒绝(公钥) - Fetching ssh git@github.com: Permission denied (publickey) git@github.com:权限被拒绝(公钥)。 但是 ssh git@github.com 有效 - git@github.com: Permission denied (publickey) . But ssh git@github.com works git@github.com:权限被拒绝(公钥) - git@github.com: Permission denied (publickey) Git Submodule git@github.com:权限被拒绝(公钥)错误 - Git Submodule git@github.com: Permission denied (publickey) error 为什么 git@github.com:Windows 中的权限被拒绝(公钥)? - Why git@github.com: Permission denied (publickey) in windows? git@github.com:权限被拒绝(公钥)错误 - git@github.com: Permission denied (publickey) ERROR 我不能做 git 推送:git@github.com:权限被拒绝(公钥) - I can't do git push: git@github.com: Permission denied (publickey) 为什么 git push 对一个仓库有效,而对另一个仓库无效? git@github.com:权限被拒绝(公钥) - Why does git push works for one repo and doesn't work for the other? git@github.com: Permission denied (publickey) Git 子模块:git@github.com:权限被拒绝(公钥)。 致命:无法从远程存储库中读取 - Git submodule: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository 我收到此错误 git@github.com: Permission denied (publickey), 当我在新 Mac 上 git push 时 - I get this error git@github.com: Permission denied (publickey), when I git push on new mac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM