git .ssh/id_rsa 失败:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9636198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:10:01  来源:igfitidea点击:

.ssh/id_rsa failed: permission denied

githerokusshgithubssh-keys

提问by Drew Verlee

I have been scanning the web/SO and read several permission denieds plea's for help I just cant find one that solves my issue in a way i understand.

我一直在扫描网络/SO 并阅读了几篇拒绝许可请求的帮助,我只是找不到以我理解的方式解决我的问题的请求。

I'm following these instructions (Getting Started with Python on Heroku/Cedar). Everything went alright until:

我正在遵循这些说明(Heroku/Cedar 上的 Python 入门)。一切顺利,直到:

drewverlee@ubuntu:~/helloflask$ source venv/bin/activate
(venv)drewverlee@ubuntu:~/helloflask$ git push heroku master

The authenticity of host 'heroku.com (50.19.85.132)' can't be established.
RSA key fingerprint is ##:##:##:##:##:##:##:##:##:##:##:## (I replaced with #)
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/drewverlee/.ssh/known_hosts).
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

(Not sure of security so i replaced the key with (#))

(不确定安全性,所以我用 (#) 替换了密钥)

I think it might be because of

我想这可能是因为

drwx------  2 root       root        1024 2012-03-08 21:26 .ssh

because

因为

drewverlee@ubuntu:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/drewverlee/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
open /home/drewverlee/.ssh/id_rsa failed: Permission denied.
Saving the key failed: /home/drewverlee/.ssh/id_rsa.

As someone with little experience in these matters i'm not sure how to undo what i have done safely as i know i'm meddling with powerful tools. Any advice on whats going on here? Let me know if i need to include more information to solve the problem.

作为在这些问题上几乎没有经验的人,我不知道如何安全地撤消我所做的事情,因为我知道我正在使用强大的工具。关于这里发生了什么的任何建议?如果我需要包含更多信息来解决问题,请告诉我。

回答by Mark Fisher

You should own the permissions to the .ssh dir in your own directory, but in your case, it's owned by root. Try

您应该拥有自己目录中 .ssh 目录的权限,但在您的情况下,它归 root 所有。尝试

cd ~
sudo chown drewverlee .ssh

and then retry creating keys and connecting.

然后重试创建密钥和连接。

回答by Tom Walpole

I had the same problem on CentOS 6. Solved it by removing selinux:

我在 CentOS 6 上遇到了同样的问题。通过删除 selinux 解决了它:

sudo yum remove selinux*

found the answer here

在这里找到了答案

note:probably not a good idea to blindly remove selinux if you don't know what you're doing though

注意:如果您不知道自己在做什么,那么盲目删除 selinux 可能不是一个好主意

回答by Phoenix87

For some reasons, the id_rsa file in the ~/.ssh folder was in read-only mode for my user (0400). I changed that to read-write (0600) with

由于某些原因, ~/.ssh 文件夹中的 id_rsa 文件对我的用户 (0400) 处于只读模式。我将其更改为读写(0600)

chmod 0600 id_rsa

and after I was obviously able to overwrite the file. I guess these are the highest permissions you can give to this file, as others wouldn't make too much sense.

在我显然能够覆盖文件之后。我想这些是您可以授予此文件的最高权限,因为其他权限没有太大意义。

回答by Koke Cacao

Since none of the answers above worked for me. I will post my answer:

因为上面的答案都不适合我。我将发布我的答案:

  1. Remove old ssh
    sudo rm -rf ~/.ssh/id_rsa sudo rm -rf ~/.ssh/id_rsa.pub
  2. Generate new ssh and use it (see https://help.github.com/enterprise/2.15/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/)
  1. 删除旧的 ssh
    sudo rm -rf ~/.ssh/id_rsa sudo rm -rf ~/.ssh/id_rsa.pub
  2. 生成新的 ssh 并使用它(参见https://help.github.com/enterprise/2.15/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/)

Why it worked:

为什么有效:

  • ssh created by sudocommand is ssh for root, not for the user. This means that ssh-add ~/.ssh/id_rsawill fail to add root ssh to a user.
  • when you try to generate new user ssh, you cannot successfully replace the old one because it was generated for root.
  • sudo命令创建的ssh 是 root 的 ssh,而不是用户的 ssh。这意味着ssh-add ~/.ssh/id_rsa将无法向用户添加 root ssh。
  • 当您尝试生成新用户 ssh 时,您无法成功替换旧用户,因为它是为 root 生成的。

(Please ask me to fix my answer if there is something wrong. thx :)

(如果有什么问题,请让我修正我的答案。谢谢:)

回答by Ian

My user (ubuntu - you can find out typing whoami) did own the ~/.ssh folder but it still wasn't letting me use the symlink (File: ~/.ssh/my_file_rsa) from ssh-keygen. So I just cd'ed into the ~/.ssh folder and didn't put an outside path for the rsa file name.

我的用户(ubuntu - 你可以发现输入 whoami)确实拥有 ~/.ssh 文件夹,但它仍然不允许我使用来自 ssh-keygen 的符号链接(文件:~/.ssh/my_file_rsa)。所以我只是 cd 进入 ~/.ssh 文件夹,并没有为 rsa 文件名放置外部路径。

whoami
ls -Al ~

cd ~/.ssh
ssh-keygen
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):  my_file_rsa