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

Dre*_*lee 15 git ssh github heroku ssh-keys

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

我正在遵循这些说明(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
Run Code Online (Sandbox Code Playgroud)

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

我想这可能是因为

drwx------  2 root       root        1024 2012-03-08 21:26 .ssh
Run Code Online (Sandbox Code Playgroud)

因为

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.
Run Code Online (Sandbox Code Playgroud)

作为在这些问题上缺乏经验的人,我不知道如何安全地撤消我已经安全的事情,因为我知道我正在干扰强大的工具.关于最新情况的任何建议?如果我需要包含更多信息来解决问题,请告诉我.

Mar*_*her 45

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

cd ~
sudo chown drewverlee .ssh
Run Code Online (Sandbox Code Playgroud)

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

  • 我发现ssh-keygen更喜欢创建.ssh目录.如果该目录已存在,则无论允许的所有权权限配置如何,都会发出权限被拒绝的消息. (5认同)

Kok*_*cao 10

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

如果您仍然记得密码并希望保留旧的 id_rsa,则使用RECOMMENDED SOLUTION,否则转到NOT RECOMMENDED SOLUTION

推荐解决方案

  1. 将权限重置为正确值
chmod -c 0644 id_rsa.pub
chmod -c 0600 id_rsa
Run Code Online (Sandbox Code Playgroud)

不推荐的解决方案

  1. 删除旧的 ssh
sudo rm -rf ~/.ssh/id_rsa
sudo rm -rf ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)
  1. 生成新的 ssh 并使用它(请参阅https://help.github.com/enterprise/2.15/user/articles/generate-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

为什么它有效:

  • 命令创建的sshsudo是针对root的ssh,而不是针对用户的。这意味着ssh-add ~/.ssh/id_rsa将无法将 root ssh 添加到用户。
  • 当您尝试生成新用户 ssh 时,您无法成功替换旧用户,因为它是为 root 生成的。

(如果有问题请让我修改我的答案。谢谢:)


Pho*_*x87 6

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

chmod 0600 id_rsa
Run Code Online (Sandbox Code Playgroud)

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