我刚刚安装了 Archbang,正在尝试克隆我的 Git 项目,这需要 SSH key 。
我过去曾在 Ubuntu 和 RedHat 机器上遵循 Github 指南取得成功,但由于某种原因,它在我的新 Arch 安装上并不适用。
我已经使用此命令成功生成了我的 SSH 公钥/私钥对:
ssh-keygen -t rsa -b 4096 -C "email@address"
但是当我继续启动 SSH 代理并添加我的公钥时,我遇到了问题。
[user@arch ~]$ eval "$(ssh-agent -s)"
bind: Permission denied
unix_listener: cannot bind to path: /tmp/ssh-ZqYqSabxjZeA/agent.9328
然而,如果我以 root 身份运行它,这是成功的:
[user@arch ~]$ eval "$(sudo ssh-agent -s)"
[sudo] password for user:
Agent pid 9146
但我很确定我不想以 root 身份执行 SSH 操作。
继续前进,当我尝试使用 ssh-add
时,我也遇到了权限错误,但这次是作为标准用户和 root:
[user@arch ~]$ ssh-add .ssh/id_rsa.pub
Could not open a connection to your authentication agent.
[user@arch ~]$ sudo ssh-add .ssh/id_rsa.pub
Could not open a connection to your authentication agent.
所以现在我真的很困惑。
我已经尝试以 root 身份打开 bash 进程来执行此操作,但是 1) 我不喜欢这个想法,并且 2) 它仍然不起作用,但这次是出于不同的原因:
[user@arch ~]$ sudo ssh-agent -s
[root@arch ~]# ssh-add .ssh/id_rsa.pub
Enter passphrase for .ssh/id_rsa.pub:
Bad passphrase, try again for .ssh/id_rsa.pub:
出于某种原因,在 root shell 中执行此操作会导致我的 SSH key 密码被拒绝;我已经尝试过多次,使用最简单的密码,所以我肯定我已经给了它正确的密码。
我很迷茫。我真的不喜欢所有这些 sudo
东西,而且我不知道为什么它似乎是必要的;我已经检查了 .ssh 目录及其文件的权限,甚至删除了整个目录并重新生成了 key ,以确保它们不是以错误的权限生成的。
有人可以帮我解决这个问题吗?我做错了什么?
编辑: 作为对建议答案的回应,我使用主目录中的套接字位置再次尝试了此操作。这些是结果:
[user@arch ~]$ mkdir -m 700 ~/.ssh
[user@arch ~]$ ssh-keygen -t rsa -b 4096 -C "email@address"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
...
[user@arch ~]$ chmod 644 .ssh/id_rsa.pub && chmod 600 .ssh/id_rsa
[user@arch ~]$ eval "$(ssh-agent -sa .ssh-agent.$$)"
Agent pid 1881
[user@arch ~]$ ssh-add .ssh/id_rsa.pub
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '.ssh/id_rsa.pub' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
在这一点上,我很困惑为什么这些权限是 Not Acceptable ,以及为什么它认为我的公钥是私钥。但我很幽默,将权限更改为 600 并尝试再次添加它。
[user@arch ~]$ chmod 600 .ssh/id_rsa.pub
[user@arch ~]$ ssh-add .ssh/id_rsa.pub
Enter passphrase for .ssh/id_rsa.pub:
Bad passphrase, try again for .ssh/id_rsa.pub:
现在我遇到了与之前类似的问题:它不喜欢我为 SSH key 创建的密码。这是怎么回事?!这真是令人费解。
最佳答案
您运行的用户似乎没有写入默认 ssh-agent 套接字位置的权限。
这应该可以解决您的问题:
ssh-agent -a ~/.ssh-agent.$$
这使用 -a
选项指定套接字位置,如 ~/.ssh-agent.$$
,即在您的主目录中。
权限问题可能是由简单的 UNIX 权限(即该用户不可写的 /tmp
)或 SELinux 或其他原因引起的。
关于git - 为什么 ssh-agent 需要 root 权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27183255/