登录时启动ssh-agent [英] Start ssh-agent on login

查看:292
本文介绍了登录时启动ssh-agent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个站点作为远程Git仓库,使用SSH别名从Bitbucket.com提取。我可以在服务器上手动启动ssh-agent,但每次通过SSH登录时都必须执行此操作。



手动启动ssh-agent:

  eval ssh-agent $ SHELL 

然后我添加代理:

  ssh-add〜/ .ssh / bitbucket_id 

然后,当我这样做时显示:

  ssh-add -l 

我很好走。有没有什么办法可以自动化这个过程,所以我不必每次登录时都这样做?服务器运行RedHat 6.2(Santiago)。

您可能会发现这非常有用:

http://mah.everybody。 org / docs / ssh



为防万一上述链接在某一天消失,我正在捕获以下解决方案的主要部分:


Joseph M. Reagle通过Daniel Starin的方式解决了这个问题:



将以下内容添加到您的 .bash_profile




  SSH_ENV =$ HOME / .ssh / environment

函数start_agent {
echo正在初始化新的SSH代理...
/ usr / bin / ssh -agent | sed's / ^ echo /#echo /'> $ {SSH_ENV}
echo成功
chmod 600$ {SSH_ENV}
。 $ {SSH_ENV}> / dev / null
/ usr / bin / ssh-add;
}

#源SSH设置(如果适用)

if [-f$ {SSH_ENV}];然后
。 $ {SSH_ENV}> / dev / null
#ps $ {SSH_AGENT_PID}在cywgin
下无效ps -ef | grep $ {SSH_AGENT_PID} | grep ssh-agent $> / dev / null || {
start_agent;
}
else
start_agent;
fi




这个版本特别好,因为它会显示如果你已经启动了ssh-agent,并且如果找不到它,它会启动它并存储这些设置,以便在下次启动shell时使用它们。



I have a site as a remote Git repo pulling from Bitbucket.com using an SSH alias. I can manually start the ssh-agent on my server but I have to do this every time I login via SSH.

I manually start the ssh-agent:

eval ssh-agent $SHELL

Then I add the agent:

ssh-add ~/.ssh/bitbucket_id

Then it shows up when I do:

ssh-add -l

And I'm good to go. Is there any way to automate this process so I don't have to do it every time I login? The server is running RedHat 6.2 (Santiago).

解决方案

Please go through this article. You may find this very useful:

http://mah.everybody.org/docs/ssh

Just in case the above link vanishes some day, I am capturing the main piece of the solution below:

This solution from Joseph M. Reagle by way of Daniel Starin:

Add this following to your .bash_profile

SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

This version is especially nice since it will see if you've already started ssh-agent and, if it can't find it, will start it up and store the settings so that they'll be usable the next time you start up a shell.

这篇关于登录时启动ssh-agent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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