我遇到了以下错误:
$ 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.
以下是我在使用PowerShell时提出的解决方案。
将以下函数添加到Microsoft.PowerShell_profile.ps1
function RunSsh($userIdentity ) {
$agent=ssh-agent
$position=$agent[0].IndexOf("=")
$ending=$agent[0].IndexOf(";")
$variableStartPosition=$agent[0].IndexOf("export")
$variableEndPosition=$agent[0].LastIndexOf(";")
$variableName=$agent[0].Substring($variableStartPosition+7,$variableEndPosition-$variableStartPosition-7)
[Environment]::SetEnvironmentVariable($variableName, $agent[0].Substring($position+1,$ending-$position-1))
$position=$agent[1].IndexOf("=")
$ending=$agent[1].IndexOf(";")
$variableStartPosition=$agent[1].IndexOf("export")
$variableEndPosition=$agent[1].LastIndexOf(";")
$variableName=$agent[1].Substring($variableStartPosition+7,$variableEndPosition-$variableStartPosition-7)
[Environment]::SetEnvironmentVariable($variableName, $agent[1].Substring($position+1,$ending-$position-1))
if($userIdentity.Length -eq 0) {
ssh-add
} else {
ssh-add $userIdentity
}
}
现在,您可以从命令行运行RunSsh,它使用~\.ssh文件夹中的标识文件,或者使用RunSsh C:\ssh\id_rsa传递标识文件,其中C:\ssh\ id_rsa是您的标识文件。
要实现这一点,您需要在路径环境变量中使用ssh-add和ssh-agent。
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
这将为您打开的每个新命令提示符窗口自动启动一个代理(如果您在一个会话中打开多个命令提示符,这是不太理想的,但至少它应该可以工作)。