无法打开与您的身份验证代理的连接

发布于 2024-09-30 12:36:51 字数 501 浏览 4 评论 0 原文

我遇到了以下错误:

$ git push heroku master
Warning: Permanently added the RSA host key for IP address '50.19.85.132' to the list of known hosts.
!  Your key with fingerprint b7:fd:15:25:02:8e:5f:06:4f:1c:af:f3:f0:c3:c2:65 is not authorized to access bitstarter.

我尝试添加密钥,但收到以下错误:

$ ssh-add ~/.ssh/id_rsa.pub
Could not open a connection to your authentication agent.

I am running into this error of:

$ git push heroku master
Warning: Permanently added the RSA host key for IP address '50.19.85.132' to the list of known hosts.
!  Your key with fingerprint b7:fd:15:25:02:8e:5f:06:4f:1c:af:f3:f0:c3:c2:65 is not authorized to access bitstarter.

I tried to add the keys and I get this error below:

$ ssh-add ~/.ssh/id_rsa.pub
Could not open a connection to your authentication agent.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

多情出卖 2024-10-07 12:36:52

对于 Windows 用户,我发现 cmd eval `ssh-agent -s` 不起作用,但使用 Git Bash 非常有用:

eval `ssh-agent -s`; ssh-add KEY_LOCATION

并确保 Windows 服务“OpenSSH Key Management”未被禁用。

For Windows users, I found cmd eval `ssh-agent -s` didn't work, but using Git Bash worked a treat:

eval `ssh-agent -s`; ssh-add KEY_LOCATION

And making sure the Windows service "OpenSSH Key Management" wasn't disabled.

烏雲後面有陽光 2024-10-07 12:36:52

放大 n3o 的回答 Windows 7 ...

我的问题确实是一些必需的环境变量没有设置,n3o 是正确的,ssh-agent 告诉你如何设置这些环境变量,但实际上并没有设置它们。

由于 Windows 不允许您执行“eval”,因此需要执行以下操作:

将 ssh-agent 的输出重定向到批处理文件

ssh-agent > temp.bat

现在使用文本编辑器(例如记事本)来编辑 temp.bat。对于前两行:

  • 在行首插入单词“set”和一个空格。
  • 删除第一个分号及其后面的所有内容。

现在删除第三行。您的 temp.bat 应如下所示:

set SSH_AUTH_SOCK=/tmp/ssh-EorQv10636/agent.10636
set SSH_AGENT_PID=8608

运行 temp.bat。这将设置 ssh-add 工作所需的环境变量。

To amplify on n3o's answer for Windows 7...

My problem was indeed that some required environment variables weren't set, and n3o is correct that ssh-agent tells you how to set those environment variables, but doesn't actually set them.

Since Windows doesn't let you do "eval," here's what to do instead:

Redirect the output of ssh-agent to a batch file with

ssh-agent > temp.bat

Now use a text editor such as Notepad to edit temp.bat. For each of the first two lines:

  • Insert the word "set" and a space at the beginning of the line.
  • Delete the first semicolon and everything that follows.

Now delete the third line. Your temp.bat should look something like this:

set SSH_AUTH_SOCK=/tmp/ssh-EorQv10636/agent.10636
set SSH_AGENT_PID=8608

Run temp.bat. This will set the environment variables that are needed for ssh-add to work.

[旋木] 2024-10-07 12:36:52

您需要启动 ssh 代理

在终端中运行:

eval $(ssh-agent -s)

You need to start the ssh agent

In your terminal, run:

eval $(ssh-agent -s)

汹涌人海 2024-10-07 12:36:52

我刚刚开始工作。打开您的 ~/.ssh/config 文件。

附加以下内容 -

Host github.com
 IdentityFile ~/.ssh/github_rsa

给我提示的页面 为 Git 设置 SSH
说单个空格缩进很重要......尽管我在这里有一个 Heroku 的配置,它没有那个空间并且工作正常。

I just got this working. Open your ~/.ssh/config file.

Append the following-

Host github.com
 IdentityFile ~/.ssh/github_rsa

The page that gave me the hint Set up SSH for Git
said that the single space indentation is important... though I had a configuration in here from Heroku that did not have that space and works properly.

少年亿悲伤 2024-10-07 12:36:52

如果您遵循这些说明,您的问题就会得到解决。

如果您使用的是 Mac 或 Linux 计算机,请键入:

eval "$(ssh-agent -s)"

如果您使用的是 Windows 计算机,请键入:

ssh-agent -s

If you follow these instructions, your problem would be solved.

If you’re on a Mac or Linux machine, type:

eval "$(ssh-agent -s)"

If you’re on a Windows machine, type:

ssh-agent -s
故事与诗 2024-10-07 12:36:52

我在 Ubuntu 上遇到了同样的问题,其他解决方案对我没有帮助。

我终于意识到我的问题是什么。我已在 /root/.ssh 文件夹中创建了 SSH 密钥,因此即使我以 root 身份运行 ssh-add ,它也无法完成其工作并一直显示:

无法打开与您的身份验证代理的连接。

我在 /home/myUsername/ 文件夹中创建了 SSH 公钥和私钥,然后使用

ssh-agent /bin/sh

然后我运行

ssh-add /home/myUsername/.ssh/id_rsa

问题就这样解决了。

注意:要访问 Git 中的存储库,请在使用 ssh-keygen -t rsa -C "your Git email here" 创建 SSH 密钥时添加 Git 密码。

I had the same problem on Ubuntu and the other solutions didn't help me.

I finally realized what my problem was. I had created my SSH keys in the /root/.ssh folder, so even when I ran ssh-add as root, it couldn't do its work and kept saying:

Could not open a connection to your authentication agent.

I created my SSH public and private keys in /home/myUsername/ folder and I used

ssh-agent /bin/sh

Then I ran

ssh-add /home/myUsername/.ssh/id_rsa

And problem was solved this way.

Note: For accessing your repository in Git, add your Git password when you are creating SSH keys with ssh-keygen -t rsa -C "your Git email here".

埖埖迣鎅 2024-10-07 12:36:52

让我提供另一个解决方案。如果您刚刚安装了 Git 1.8.2.2 或类似版本,并且想要启用 SSH,请按照写得很好的 方向

一直到步骤 5.6,您可能会遇到一些轻微的障碍。如果 SSH 代理已在运行,则重新启动 bash 时可能会收到以下错误消息

Could not open a connection to your authentication agent

如果这样做,请使用以下命令查看是否有多个 ssh-agent 进程正在运行

ps aux | grep ssh

如果您看到多个 ssh-agent 服务,您将需要终止所有这些进程。按如下所示使用kill 命令(PID 在您的计算机上是唯一的)

kill <PID>

示例:

kill 1074

删除所有 ssh-agent 进程后,运行 px aux |再次运行 grep ssh 命令以确保它们消失,然后重新启动 Bash。

瞧,您现在应该得到类似这样的信息:

Initializing new SSH agent...
succeeded
Enter passphrase for /c/Users/username/.ssh/id_rsa:

现在您可以继续执行步骤 5.7 及后续步骤。

Let me offer another solution. If you have just installed Git 1.8.2.2 or thereabouts, and you want to enable SSH, follow the well-writen directions.

Everything through to Step 5.6 where you might encounter a slight snag. If an SSH agent is already be running you could get the following error message when you restart bash

Could not open a connection to your authentication agent

If you do, use the following command to see if more than one ssh-agent process is running

ps aux | grep ssh

If you see more than one ssh-agent service, you will need to kill all of these processes. Use the kill command as follows (the PID will be unique on your computer)

kill <PID>

Example:

kill 1074

After you have removed all of the ssh-agent processes, run the px aux | grep ssh command again to be sure they are gone, then restart Bash.

Voila, you should now get something like this:

Initializing new SSH agent...
succeeded
Enter passphrase for /c/Users/username/.ssh/id_rsa:

Now you can continue on Step 5.7 and beyond.

橙幽之幻 2024-10-07 12:36:52

这将运行 SSH 代理并仅在您第一次需要时进行身份验证,而不是每次打开 Bash 终端时进行身份验证。它可用于一般使用 SSH 的任何程序,包括 ssh 本身和 <代码>scp。只需将其添加到 /etc/profile.d/ssh-helper.sh 中:

ssh-auth() {
    # Start the SSH agent only if not running
    [[ -z $(ps | grep ssh-agent) ]] && echo $(ssh-agent) > /tmp/ssh-agent-data.sh

    # Identify the running SSH agent
    [[ -z $SSH_AGENT_PID ]] && source /tmp/ssh-agent-data.sh > /dev/null

    # Authenticate (change key path or make a symlink if needed)
    [[ -z $(ssh-add -l | grep "/home/$(whoami)/.ssh/id_rsa") ]] && ssh-add
}

# You can repeat this for other commands using SSH
git() { ssh-auth; command git "$@"; }

注意:这是对此问题的回答,已与此合并。
这个问题是针对 Windows 7 的,这意味着我的答案是针对 Cygwin/MSYS/MSYS2 的。这似乎适用于某些 Unix,我不认为 SSH 代理需要这样管理

This will run the SSH agent and authenticate only the first time you need it, not every time you open your Bash terminal. It can be used for any program using SSH in general, including ssh itself and scp. Just add this to /etc/profile.d/ssh-helper.sh:

ssh-auth() {
    # Start the SSH agent only if not running
    [[ -z $(ps | grep ssh-agent) ]] && echo $(ssh-agent) > /tmp/ssh-agent-data.sh

    # Identify the running SSH agent
    [[ -z $SSH_AGENT_PID ]] && source /tmp/ssh-agent-data.sh > /dev/null

    # Authenticate (change key path or make a symlink if needed)
    [[ -z $(ssh-add -l | grep "/home/$(whoami)/.ssh/id_rsa") ]] && ssh-add
}

# You can repeat this for other commands using SSH
git() { ssh-auth; command git "$@"; }

Note: this is an answer to this question, which has been merged with this one.
That question was for Windows 7, meaning my answer was for Cygwin/MSYS/MSYS2. This one seems for some Unix, where I wouldn't expect the SSH agent needing to be managed like this
.

伤痕我心 2024-10-07 12:36:52

许多答案都回答了运行 ssh-agent 的基本解决方案。但是,多次运行 ssh-agent(每个打开的终端或每次远程登录)将在内存中创建许多运行的 ssh-agent 副本。建议避免该问题的脚本很长,需要编写和/或复制单独的文件,或者需要在 ~/.profile~/.schrc.让我建议简单的两个字符串解决方案:

对于shbash等:

# ~/.profile
if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -s > ~/.ssh-agent.sh; fi
. ~/.ssh-agent.sh

对于cshtcsh 等:

# ~/.schrc
sh -c 'if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -c > ~/.ssh-agent.tcsh; fi'
eval `cat ~/.ssh-agent.tcsh`

这里是什么:

  • 按名称和当前用户搜索进程ssh-agent
  • 通过调用ssh-agent创建适当的shell脚本文件并运行< code>ssh-agent 本身,如果没有找到当前用户 ssh-agent 进程,
  • 则评估创建的 shell 脚本,配置适当的环境

没有必要保护创建的 shell 脚本 ~/.ssh -agent.tcsh~/.ssh-agent.sh 来自其他用户的访问,因为:与 ssh-agent 的首次通信是通过受保护的套接字处理的其他用户无法访问,此时其他用户可以通过 /tmp/ 目录中的枚举文件简单地找到 ssh-agent 套接字。就访问 ssh-agent 进程而言,这是相同的事情。

The basic solution to run ssh-agent is answered in many answers. However runing ssh-agent many times (per each opened terminal or per remote login) will create a many copies ot ssh-agent running in memory. The scripts which is suggested to avoid that problem is long and need to write and/or copy separated file or need to write too many strings in ~/.profile or ~/.schrc. Let me suggest simple two string solution:

For sh, bash, etc:

# ~/.profile
if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -s > ~/.ssh-agent.sh; fi
. ~/.ssh-agent.sh

For csh, tcsh, etc:

# ~/.schrc
sh -c 'if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -c > ~/.ssh-agent.tcsh; fi'
eval `cat ~/.ssh-agent.tcsh`

What is here:

  • search the process ssh-agent by name and by current user
  • create appropriate shell script file by calling ssh-agent and run ssh-agent itself if no current user ssh-agent process found
  • evaluate created shell script which configure appropriate environment

It is not necessary to protect created shell script ~/.ssh-agent.tcsh or ~/.ssh-agent.sh from another users access because: at-first communication with ssh-agent is processed through protected socket which is not accessible to another users, and at-second another users can found ssh-agent socket simple by enumeration files in /tmp/ directory. As far as about access to ssh-agent process it is the same things.

喜爱皱眉﹌ 2024-10-07 12:36:52

在 Windows 10 中,使用命令提示符终端,以下操作对我有用:

ssh-agent cmd 
ssh-add

然后系统会要求您输入密码:

Enter passphrase for /c/Users/username/.ssh/id_rsa:

In Windows 10, using the Command Prompt terminal, the following works for me:

ssh-agent cmd 
ssh-add

You should then be asked for a passphrase after this:

Enter passphrase for /c/Users/username/.ssh/id_rsa:
薯片软お妹 2024-10-07 12:36:52

请尝试以下操作:

ssh-agent sh -c 'ssh-add && git push heroku master'

Try the following:

ssh-agent sh -c 'ssh-add && git push heroku master'
七堇年 2024-10-07 12:36:52

连接到服务器时使用参数 -A,例如:

ssh -A root@myhost

来自手册页:

-A Enables forwarding of the authentication agent connection.  
   This can also be specified on a per-host basis in a configuration file.

   Agent forwarding should be enabled with caution.  Users with the ability to bypass file permissions on the remote host (for the agent's
   UNIX-domain socket) can access the local agent through the forwarded 
   connection.  An attacker cannot obtain key material from the agent,
   however they can perform operations on the keys that enable them to
   authenticate using the identities loaded into the agent.

Use parameter -A when you connect to server, example:

ssh -A root@myhost

from man page :

-A Enables forwarding of the authentication agent connection.  
   This can also be specified on a per-host basis in a configuration file.

   Agent forwarding should be enabled with caution.  Users with the ability to bypass file permissions on the remote host (for the agent's
   UNIX-domain socket) can access the local agent through the forwarded 
   connection.  An attacker cannot obtain key material from the agent,
   however they can perform operations on the keys that enable them to
   authenticate using the identities loaded into the agent.
黄昏下泛黄的笔记 2024-10-07 12:36:52

当我启动 ssh-agent 时,当它已经运行时,我遇到了这个问题。看来多个实例相互冲突。

要查看 ssh-agent 是否已在运行,请检查 SSH_AGENT_SOCK 环境变量的值:

echo $SSH_AGENT_SOCK

如果已设置,则代理可能正在运行。

要检查是否有多个 ssh-agent 正在运行,您可以查看:

ps -ef | grep ssh

当然,那么您应该终止您创建的任何其他实例。

I had this problem, when I started ssh-agent, when it was already running. It seems that the multiple instances conflict with each other.

To see if ssh-agent is already running, check the value of the SSH_AGENT_SOCK environment variable with:

echo $SSH_AGENT_SOCK

If it is set, then the agent is presumably running.

To check if you have more than one ssh-agent running, you can review:

ps -ef | grep ssh

Of course, then you should kill any additional instances that you created.

情感失落者 2024-10-07 12:36:52

请阅读 user456814 的回答以获取解释。在这里我只尝试自动化修复。

如果您使用带有 Bash 的 Cygwin 终端,请将以下内容添加到 $HOME/ .bashrc 文件。这只会在第一个 Bash 终端中启动 ssh-agent 一次,并将密钥添加到 ssh-agent 中。 (我不确定 Linux 上是否需要这样做。)

###########################
# start ssh-agent for
# ssh authentication with github.com
###########################
SSH_AUTH_SOCK_FILE=/tmp/SSH_AUTH_SOCK.sh
if [ ! -e $SSH_AUTH_SOCK_FILE ]; then
    # need to find SSH_AUTH_SOCK again.
    # restarting is an easy option
    pkill ssh-agent
fi
# check if already running
SSH_AGENT_PID=`pgrep ssh-agent`
if [ "x$SSH_AGENT_PID" == "x" ]; then
#   echo "not running. starting"
    eval $(ssh-agent -s) > /dev/null
    rm -f $SSH_AUTH_SOCK_FILE
    echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" > $SSH_AUTH_SOCK_FILE
    ssh-add $HOME/.ssh/github.com_id_rsa 2>&1 > /dev/null
#else
#   echo "already running"
fi
source $SSH_AUTH_SOCK_FILE

不要忘记在“ssh-add”命令中添加正确的密钥。

Read user456814's answer for explanations. Here I only try to automate the fix.

If you using a Cygwin terminal with Bash, add the following to the $HOME/.bashrc file. This only starts ssh-agent once in the first Bash terminal and adds the keys to ssh-agent. (I am not sure if this is required on Linux.)

###########################
# start ssh-agent for
# ssh authentication with github.com
###########################
SSH_AUTH_SOCK_FILE=/tmp/SSH_AUTH_SOCK.sh
if [ ! -e $SSH_AUTH_SOCK_FILE ]; then
    # need to find SSH_AUTH_SOCK again.
    # restarting is an easy option
    pkill ssh-agent
fi
# check if already running
SSH_AGENT_PID=`pgrep ssh-agent`
if [ "x$SSH_AGENT_PID" == "x" ]; then
#   echo "not running. starting"
    eval $(ssh-agent -s) > /dev/null
    rm -f $SSH_AUTH_SOCK_FILE
    echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" > $SSH_AUTH_SOCK_FILE
    ssh-add $HOME/.ssh/github.com_id_rsa 2>&1 > /dev/null
#else
#   echo "already running"
fi
source $SSH_AUTH_SOCK_FILE

Don’t forget to add your correct keys in the "ssh-add" command.

灵芸 2024-10-07 12:36:52

当我试图让它在 Windows 上工作并通过 SSH 连接到存储时,我遇到了类似的问题。

这是对我有用的解决方案。

  1. 原来我在我的 Windows 机器上运行 Pageant ssh 代理 - 我会检查您正在运行的内容。我怀疑它是 Pageant,因为它是 PuTTY 和 WinSCP 的默认设置。

  2. ssh-add 无法从命令行使用此类代理

  3. 您需要通过 Pageant UI 窗口添加私钥,您可以通过双击任务栏中的 Pageant 图标来获取该私钥(启动后) .

  4. 在将密钥添加到 Pageant 之前,您需要将其转换为 PPK 格式。完整说明可在此处 如何将SSH密钥转换为ppk格式

  5. 就是这样。将密钥上传到存储区后,我就可以使用 Sourcetree 创建本地存储库并克隆远程存储库。

I had a similar problem when I was trying to get this to work on Windows to connect to the stash via SSH.

Here is the solution that worked for me.

  1. Turns out I was running the Pageant ssh agent on my Windows box - I would check what you are running. I suspect it is Pageant as it comes as default with PuTTY and WinSCP.

  2. The ssh-add does not work from command line with this type of agent

  3. You need to add the private key via the Pageant UI window which you can get by double-clicking the Pageant icon in the taskbar (once it is started).

  4. Before you add the key to Pageant you need to convert it to PPK format. Full instructions are available here How to convert SSH key to ppk format

  5. That is it. Once I uploaded my key to stash I was able to use Sourcetree to create a local repository and clone the remote.

梓梦 2024-10-07 12:36:52

对于 Windows 10 中内置的 Bash,我将其添加到文件 .bash_profile

if [ -z $SSH_AUTH_SOCK ]; then
    if [ -r ~/.ssh/env ]; then
            source ~/.ssh/env
            if [ `ps -p $SSH_AGENT_PID | wc -l` = 1 ]; then
                    rm ~/.ssh/env
                    unset SSH_AUTH_SOCK
            fi
    fi
fi

if [ -z $SSH_AUTH_SOCK ]; then
    ssh-agent -s | sed 's/^echo/#echo/'> ~/.ssh/env
    chmod 600 ~/.ssh/env
    source ~/.ssh/env > /dev/null 2>&1
fi

For Bash built into Windows 10, I added this to file .bash_profile:

if [ -z $SSH_AUTH_SOCK ]; then
    if [ -r ~/.ssh/env ]; then
            source ~/.ssh/env
            if [ `ps -p $SSH_AGENT_PID | wc -l` = 1 ]; then
                    rm ~/.ssh/env
                    unset SSH_AUTH_SOCK
            fi
    fi
fi

if [ -z $SSH_AUTH_SOCK ]; then
    ssh-agent -s | sed 's/^echo/#echo/'> ~/.ssh/env
    chmod 600 ~/.ssh/env
    source ~/.ssh/env > /dev/null 2>&1
fi
喜爱皱眉﹌ 2024-10-07 12:36:52

Git Bash .wikipedia.org/wiki/Windows_8.1" rel="nofollow noreferrer">Windows 8.1 E,我的解决方案如下:

eval $(ssh-agent) > /dev/null
ssh-add ~/.ssh/id_rsa

Using Git Bash on Windows 8.1 E, my resolution was as follows:

eval $(ssh-agent) > /dev/null
ssh-add ~/.ssh/id_rsa
孤独岁月 2024-10-07 12:36:52

我通过强制停止(终止)git 进程(ssh 代理),然后卸载 Git,然后再次安装 Git 解决了该错误。

I resolved the error by force stopping (killed) git processes (ssh agent), then uninstalling Git, and then installing Git again.

柠檬心 2024-10-07 12:36:51

您启动ssh-agent了吗?

您可能需要在运行 ssh-add 命令之前启动 ssh-agent

eval `ssh-agent -s`
ssh-add

请注意,这将启动 Windows 上的 msysgit Bash 代理。如果您使用不同的 shell 或操作系统,则可能需要使用该命令的变体,例如 其他答案

请参阅以下答案:

  1. ssh-add 抱怨:无法打开与身份验证代理的连接
  2. Git推送需要用户名和密码(包含如何使用ssh-agent的详细说明)
  3. 如何运行(git/ssh) 身份验证代理?
  4. 无法打开与您的身份验证代理的连接< /a>

要自动启动 ssh-agent 并允许单个实例在多个控制台窗口中工作,请参阅登录时启动 ssh-agent

为什么我们需要使用 eval 而不仅仅是 ssh-agent

为了使用 ssh-agent,SSH 需要两件事:一个在后台运行的 ssh-agent 实例,以及一个环境变量集,该变量集告诉 SSH 应使用哪个套接字来连接到代理 (SSH_AUTH_SOCK IIRC)。如果您只运行 ssh-agent,那么代理将启动,但 SSH 将不知道在哪里找到它。

来自此评论

公钥与私钥

此外,每当我使用 ssh-add 时,我总是向其添加私钥。文件 ~/.ssh/id_rsa.pub 看起来像一个公钥,我不确定这是否有效。您有 ~/.ssh/id_rsa 文件吗?如果您在文本编辑器中打开它,它会说它是私钥吗?

Did You Start ssh-agent?

You might need to start ssh-agent before you run the ssh-add command:

eval `ssh-agent -s`
ssh-add

Note that this will start the agent for msysgit Bash on Windows. If you're using a different shell or operating system, you might need to use a variant of the command, such as those listed in the other answers.

See the following answers:

  1. ssh-add complains: Could not open a connection to your authentication agent
  2. Git push requires username and password (contains detailed instructions on how to use ssh-agent)
  3. How to run (git/ssh) authentication agent?.
  4. Could not open a connection to your authentication agent

To automatically start ssh-agent and allow a single instance to work in multiple console windows, see Start ssh-agent on login.

Why do we need to use eval instead of just ssh-agent?

SSH needs two things in order to use ssh-agent: an ssh-agent instance running in the background, and an environment variable set that tells SSH which socket it should use to connect to the agent (SSH_AUTH_SOCK IIRC). If you just run ssh-agent then the agent will start, but SSH will have no idea where to find it.

from this comment.

Public vs Private Keys

Also, whenever I use ssh-add, I always add private keys to it. The file ~/.ssh/id_rsa.pub looks like a public key, I'm not sure if that will work. Do you have a ~/.ssh/id_rsa file? If you open it in a text editor, does it say it's a private key?

高跟鞋的旋律 2024-10-07 12:36:51

我尝试了其他解决方案均无济于事。我做了更多研究,发现以下命令有效。我使用的是 Windows 7 和 Git Bash

eval $(ssh-agent)

更多信息请参见:https://coderwall.com/p/rdi_wq (

I tried the other solutions to no avail. I made more research and found that the following command worked. I am using Windows 7 and Git Bash.

eval $(ssh-agent)

More information in: https://coderwall.com/p/rdi_wq (web archive version)

笑咖 2024-10-07 12:36:51

以下命令对我有用。我正在使用 CentOS。

exec ssh-agent bash

The following command worked for me. I am using CentOS.

exec ssh-agent bash
苦妄 2024-10-07 12:36:51

无法打开与身份验证代理的连接

要解决此错误:

bash:

$ eval `ssh-agent -s`

tcsh:

$ eval `ssh-agent -c`

然后像平常一样使用 ssh-add


热门提示:

我总是忘记为上述 ssh-agent 命令输入什么内容,因此我在 .bashrc 文件中创建了一个别名,如下所示:

alias ssh-agent-cyg='eval `ssh-agent -s`'

现在而不是使用 < code>ssh-agent,我可以使用 ssh-agent-cyg

例如

$ ssh-agent-cyg
SSH_AUTH_SOCK=/tmp/ssh-n16KsxjuTMiM/agent.32394; export SSH_AUTH_SOCK;
SSH_AGENT_PID=32395; export SSH_AGENT_PID;
echo Agent pid 32395;
$ ssh-add ~/.ssh/my_pk

修复的原始来源:

http://cygwin.com/ml/cygwin/2011-10/msg00313.html

Could not open a connection to your authentication agent

To resolve this error:

bash:

$ eval `ssh-agent -s`

tcsh:

$ eval `ssh-agent -c`

Then use ssh-add as you normally would.


Hot Tip:

I was always forgetting what to type for the above ssh-agent commands, so I created an alias in my .bashrc file like this:

alias ssh-agent-cyg='eval `ssh-agent -s`'

Now instead of using ssh-agent, I can use ssh-agent-cyg

E.g.

$ ssh-agent-cyg
SSH_AUTH_SOCK=/tmp/ssh-n16KsxjuTMiM/agent.32394; export SSH_AUTH_SOCK;
SSH_AGENT_PID=32395; export SSH_AGENT_PID;
echo Agent pid 32395;
$ ssh-add ~/.ssh/my_pk

Original Source of fix:

http://cygwin.com/ml/cygwin/2011-10/msg00313.html

抠脚大汉 2024-10-07 12:36:51

MsysGit 或 Cygwin

如果您使用 Msysgit 或 Cygwin,您可以在 SSH- 找到一个很好的教程msysgit、cygwin 和 bash 中的代理

  1. 将名为 .bashrc 的文件添加到您的主文件夹。

  2. 打开文件并粘贴:

    #!/bin/bash
    评估 `ssh-agent -s`
    ssh-添加
    
  3. 这假设您的密钥位于传统的 ~/.ssh/id_rsa 位置。如果不是,请在 ssh-add 命令后添加完整路径。

  4. 添加或创建包含内容的文件~/.ssh/config

    ForwardAgent 是
    

    在原始教程中,ForwardAgent 参数是Yes,但这是一个拼写错误。全部使用小写,否则会出现错误。

  5. 重新启动 Msysgit。它会要求您输入一次密码,仅此而已(直到您结束会话,或者您的 ssh 代理被终止。)

Mac/OS X

如果您不想每次打开时都启动新的 ssh 代理在终端上,查看钥匙串。我现在在 Mac 上,所以我使用了教程 ssh-agent 与 zsh 和Mac OS X 上的钥匙串 来设置它,但我确信 Google 搜索会提供大量有关 Windows 的信息。

更新:Mac 上更好的解决方案是将密钥添加到 Mac OS 钥匙串:

ssh-add -K ~/.ssh/id_rsa

就这么简单。

MsysGit or Cygwin

If you're using Msysgit or Cygwin you can find a good tutorial at SSH-Agent in msysgit and cygwin and bash:

  1. Add a file called .bashrc to your home folder.

  2. Open the file and paste in:

    #!/bin/bash
    eval `ssh-agent -s`
    ssh-add
    
  3. This assumes that your key is in the conventional ~/.ssh/id_rsa location. If it isn't, include a full path after the ssh-add command.

  4. Add to or create file ~/.ssh/config with the contents

    ForwardAgent yes
    

    In the original tutorial the ForwardAgent param is Yes, but it's a typo. Use all lowercase or you'll get errors.

  5. Restart Msysgit. It will ask you to enter your passphrase once, and that's it (until you end the session, or your ssh-agent is killed.)

Mac/OS X

If you don't want to start a new ssh-agent every time you open a terminal, check out Keychain. I'm on a Mac now, so I used the tutorial ssh-agent with zsh & keychain on Mac OS X to set it up, but I'm sure a Google search will have plenty of info for Windows.

Update: A better solution on Mac is to add your key to the Mac OS Keychain:

ssh-add -K ~/.ssh/id_rsa

Simple as that.

夏日落 2024-10-07 12:36:51

运行

ssh-agent bash
ssh-add

要获取更多详细信息,您可以搜索

ssh-agent

或运行

man ssh-agent

Run

ssh-agent bash
ssh-add

To get more details you can search

ssh-agent

or run

man ssh-agent
走野 2024-10-07 12:36:51

ssh-add 和 ssh(假设您正在使用 openssh 实现)需要一个环境变量来知道如何与 ssh 代理通信。如果您在与现在使用的命令提示符窗口不同的命令提示符窗口中启动代理,或者启动不正确,则 ssh-add 和 ssh 都不会看到该环境变量集(因为环境变量是在本地设置的) 到它所设置的命令提示符)。

你没有说你正在使用哪个版本的 ssh,但如果你使用 cygwin,你可以使用 Cygwin 上的 SSH 代理

# Add to your Bash config file
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
    eval `$SSHAGENT $SSHAGENTARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

这将为您打开的每个新命令提示符窗口自动启动代理(如果您打开多个命令,这不是最佳选择)在一个会话中提示,但至少它应该起作用)。

ssh-add and ssh (assuming you are using the openssh implementations) require an environment variable to know how to talk to the ssh agent. If you started the agent in a different command prompt window to the one you're using now, or if you started it incorrectly, neither ssh-add nor ssh will see that environment variable set (because the environment variable is set locally to the command prompt it's set in).

You don't say which version of ssh you're using, but if you're using cygwin's, you can use this recipe from SSH Agent on Cygwin:

# Add to your Bash config file
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
    eval `$SSHAGENT $SSHAGENTARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

This will start an agent automatically for each new command prompt window that you open (which is suboptimal if you open multiple command prompts in one session, but at least it should work).

黑寡妇 2024-10-07 12:36:51

我在 Linux 上遇到了同样的问题,这就是我所做的:

基本上,命令 ssh-agent 启动代理,但它并没有真正设置它运行的环境变量。它只是将这些变量输出到 shell。

您需要:

eval `ssh-agent`

然后执行 ssh-add。请参阅无法打开与您的连接身份验证代理

I faced the same problem for Linux, and here is what I did:

Basically, the command ssh-agent starts the agent, but it doesn't really set the environment variables for it to run. It just outputs those variables to the shell.

You need to:

eval `ssh-agent`

and then do ssh-add. See Could not open a connection to your authentication agent.

ペ泪落弦音 2024-10-07 12:36:51

我没有使用 ssh-agent -s ,而是使用 eval `ssh-agent -s` 来解决这个问题。

这是我一步一步执行的操作(在 Git Bash):

  1. 清理了位于 C:\user\\.ssh\.ssh 文件
  2. 夹生成了一个新的 SSH 密钥:
    ssh-keygen -t rsa -b 4096 -C "[电子邮件受保护]< /a>"
  3. 检查是否有任何进程 ID(ssh 代理)已在运行。
    PS 辅助 | grep ssh
  4. (可选)如果在步骤 3 中发现任何内容,则杀死它们
    kill
  5. 启动 SSH 代理
    $ eval `ssh-agent -s`
  6. 将步骤 2 中生成的 SSH 密钥添加到 SSH 代理
    ssh-add ~/.ssh/id_rsa

Instead of using ssh-agent -s, I used eval `ssh-agent -s` to solve this issue.

Here is what I performed step by step (step 2 onwards on Git Bash):

  1. Cleaned up my .ssh folder at C:\user\<username>\.ssh\
  2. Generated a new SSH key:
    ssh-keygen -t rsa -b 4096 -C "[email protected]"
  3. Check if any process id(ssh agent) is already running.
    ps aux | grep ssh
  4. (Optional) If found any in step 3, kill those
    kill <pids>
  5. Started the SSH agent
    $ eval `ssh-agent -s`
  6. Added SSH key generated in step 2 to the SSH agent
    ssh-add ~/.ssh/id_rsa
橘虞初梦 2024-10-07 12:36:51

尝试执行以下步骤:

  1. 打开 Git Bash 并运行:cd ~/.ssh

  2. 尝试运行代理:eval $(ssh-agent)

  3. 现在,您可以运行以下命令:ssh-add -l

Try to do the following steps:

  1. Open Git Bash and run: cd ~/.ssh

  2. Try to run agent: eval $(ssh-agent)

  3. Right now, you can run the following command: ssh-add -l

攀登最高峰 2024-10-07 12:36:51

在 Windows 10 中,我尝试了此处列出的所有答案,但似乎都不起作用。事实上,他们给出了线索​​。要解决一个问题,只需要三个命令。 这个问题的想法是ssh-add需要使用当前ssh-agent sock文件路径和pid号来设置SSH_AUTH_SOCK和SSH_AGENT_PID环境变量。

ssh-agent -s > temp.txt

这会将ssh-agent的输出保存在一个文件。文本文件内容将如下所示:

SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3044; export SSH_AGENT_PID;
echo Agent pid 3044;

从文本文件中复制类似“/tmp/ssh-kjmxRb2764/agent.2764”的内容,然后直接在控制台中运行以下命令:

set SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764

从文本文件中复制类似“3044”的内容并直接在控制台中运行以下命令:

set SSH_AGENT_PID=3044

现在,当为当前控制台会话设置环境变量(SSH_AUTH_SOCK 和 SSH_AGENT_PID)时,运行 ssh-add 命令,连接到 ssh 代理将不会再次失败。

In Windows 10 I tried all answers listed here, but none of them seemed to work. In fact, they give a clue. To solve a problem, simply you need three commands. The idea of this problem is that ssh-add needs the SSH_AUTH_SOCK and SSH_AGENT_PID environment variables to be set with the current ssh-agent sock file path and pid number.

ssh-agent -s > temp.txt

This will save the output of ssh-agent in a file. The text file content will be something like this:

SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3044; export SSH_AGENT_PID;
echo Agent pid 3044;

Copy something like "/tmp/ssh-kjmxRb2764/agent.2764" from the text file and run the following command directly in the console:

set SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764

Copy something like "3044" from the text file and run the following command directly in the console:

set SSH_AGENT_PID=3044

Now when environment variables (SSH_AUTH_SOCK and SSH_AGENT_PID) are set for the current console session, run your ssh-add command and it will not fail again to connect to ssh agent.

许你一世情深 2024-10-07 12:36:51

我遇到的一件事是,eval 对我使用 Cygwin 不起作用,对我有用的是 ssh-agent ssh-add id_rsa

之后我遇到了我的私钥太开放的问题,我设法找到了解决方案(来自 这里):

chgrp Users id_rsa

最后

chmod 600 id_rsa

我能够使用:

ssh-agent ssh-add id_rsa

One thing I came across was that eval did not work for me using Cygwin, what worked for me was ssh-agent ssh-add id_rsa.

After that I came across an issue that my private key was too open, the solution I managed to find for that (from here):

chgrp Users id_rsa

as well as

chmod 600 id_rsa

finally I was able to use:

ssh-agent ssh-add id_rsa
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文