SSH密钥要求在启动代理后输入密码 [英] SSH Key ask to enter passphrase after start-agent

查看:290
本文介绍了SSH密钥要求在启动代理后输入密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是我的bachrc文件:



pre> #注意:不应该使用〜/ .ssh / environment,因为
#在SSH中已经有了不同的用途。

env = $ HOME / .ssh / agent.env

#注意:不要打扰检查SSH_AGENT_PID。它本身并未使用
#,它甚至可能是不正确的
#(例如,通过SSH使用代理转发时)。

agent_is_running(){
if [$ SSH_AUTH_SOCK];然后
#ssh-add返回:
#0 =代理正在运行,有键
#1 =代理正在运行,没有键
#2 =代理未运行
ssh -add〜/ .ssh / id_rsa〜/ .ssh / id_rsa_2 -l> / dev / null 2>& 1 || [$? -eq 1]
else
false
fi
}

agent_has_keys(){
ssh-add -l> / dev / null 2>& 1
}

agent_load_env(){
。 $ env> / dev / null
}

agent_start(){
(umask 077; ssh-agent>$ env)
。 $ env> / dev / null
}

if! agent_is_running;那么
agent_load_env
fi

#如果你的密钥没有存储在〜/ .ssh / id_rsa或〜/ .ssh / id_dsa中,你需要
#在ssh-add
之后粘贴正确的路径if! agent_is_running;然后
agent_start
ssh-add〜/ .ssh / id_rsa〜/ .ssh / id_rsa_2
elif! agent_has_keys;然后
ssh-add〜/ .ssh / id_rsa〜/ .ssh / id_rsa_2
fi

unset env

agent_stop(){
if [$ {SSH_AGENT_PID + 1} == 1];那么
ssh-add -D
ssh-agent -k> / dev / null 2>& 1
unset SSH_AGENT_PID
unset SSH_AUTH_SOCK
fi
}

agent_stop

为什么我要打电话给agent_stop?
$ b 。我发现当agent_stop被调用时,所有ssh密钥都会从代理中删除,然后再次打开git bash时,代理会自动添加ssh密钥。

但是只有id_rsa不会提示密码,每次都会提示id_rsa_2提示。

P / S:id_rsa_2的公钥已添加到Bitbucket中。



我错过了什么

解决方案

注意:如果您生成一个不含密码的ssh密钥

 cd 
ssh-keygen -t rsa -f.ssh / mykey-Ckey for xxx acess-q -P

然后你根本不需要ssh-agent

I have 2 ssh key for 2 different accounts on Bitbucket.

The below is my bachrc file:

# Note: ~/.ssh/environment should not be used, as it
#       already has a different purpose in SSH.

env=$HOME/.ssh/agent.env

# Note: Don't bother checking SSH_AGENT_PID. It's not used
#       by SSH itself, and it might even be incorrect
#       (for example, when using agent-forwarding over SSH).

agent_is_running() {
    if [ "$SSH_AUTH_SOCK" ]; then
        # ssh-add returns:
        #   0 = agent running, has keys
        #   1 = agent running, no keys
        #   2 = agent not running
        ssh-add ~/.ssh/id_rsa ~/.ssh/id_rsa_2 -l >/dev/null 2>&1 || [ $? -eq 1 ]
    else
        false
    fi
}

agent_has_keys() {
    ssh-add -l >/dev/null 2>&1
}

agent_load_env() {
    . "$env" >/dev/null
}

agent_start() {
    (umask 077; ssh-agent >"$env")
    . "$env" >/dev/null
}

if ! agent_is_running; then
    agent_load_env
fi

# if your keys are not stored in ~/.ssh/id_rsa or ~/.ssh/id_dsa, you'll need
# to paste the proper path after ssh-add
if ! agent_is_running; then
    agent_start
    ssh-add ~/.ssh/id_rsa ~/.ssh/id_rsa_2
elif ! agent_has_keys; then
    ssh-add ~/.ssh/id_rsa ~/.ssh/id_rsa_2
fi

unset env

agent_stop() {
    if [ ${SSH_AGENT_PID+1} == 1 ]; then
        ssh-add -D
        ssh-agent -k > /dev/null 2>&1
        unset SSH_AGENT_PID
        unset SSH_AUTH_SOCK
    fi
}

agent_stop

Why do I call agent_stop?

That's for testing. I figured out that when agent_stop is called, all ssh keys are removed from agent and then when opened git bash again, the agent automatically adds ssh keys.

But only id_rsa doesn't prompt passphrase, the id_rsa_2 prompt everytime.

P/S: The public key of id_rsa_2 is added on Bitbucket.

What am I missing for this?

解决方案

Note: if you generate an ssh key without passphrase

cd
ssh-keygen -t rsa -f ".ssh/mykey" -C "key for xxx acess" -q -P ""

Then you don't need ssh-agent at all

这篇关于SSH密钥要求在启动代理后输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆