我遇到了以下错误:
$ 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.
阅读用户456814的答案以获得解释。这里我只尝试自动修复。
如果您在Bash中使用Cygwin终端,请将以下内容添加到$HOME/.bashrc文件中。这只会在第一个Bash终端中启动一次ssh代理,并将密钥添加到ssh代理。(我不确定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”命令中添加正确的密钥。
在~/.ssh中创建配置文件并设置PERMANENTLY,主机可以是ip/domain它没有在windows10中测试
Host 20.16.4.5
IdentityFile ~/.ssh/id_rsa_ec2
如果你想过去,就去酒吧。在aws中使用1将PEM中的私钥复制到.ssh文件夹
$ cp /path/to/my-aws-ec2-instance.pem ~/.ssh/id_rsa_ec2
2生成并保存公钥
ssh-keygen -y -f /path/to/my-aws-ec2-instance.pem > ~/.ssh/id_rsa_ec2.pub
AND SET(手动将密钥永久添加到代理),然后使用ec2而不使用pemssh软件ec2-user@ec2-ip.compute-x.amazonaws.com
这将只在您第一次需要时运行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代理需要这样管理。