30

我一直在扫描 web/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

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

我想可能是因为

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

因为

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.

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

4

5 回答 5

73

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

cd ~
sudo chown drewverlee .ssh

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

于 2012-03-09T15:09:06.730 回答
7

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

chmod 0600 id_rsa

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

于 2017-07-22T11:47:59.987 回答
5

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

如果您还记得密码并想保留旧的 id_rsa,则使用RECOMMENDED SOLUTION,否则转到NOT RECOMMENDED SOLUTION

推荐的解决方案

  1. 将权限重置为正确的值
chmod -c 0644 id_rsa.pub
chmod -c 0600 id_rsa

不推荐的解决方案

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

为什么有效:

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

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

于 2018-12-27T01:17:50.920 回答
3

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

sudo yum remove selinux*

在这里找到了答案

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

于 2012-05-22T16:26:11.640 回答
1

我的用户(ubuntu - 你可以找到键入 whoami)确实拥有 ~/.ssh 文件夹,但它仍然不允许我使用来自 ssh-keygen 的符号链接(文件:~/.ssh/my_file_rsa)。所以我只是 cd'ed 进入 ~/.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
于 2018-09-27T22:10:32.287 回答