📌  相关文章
📜  如何检查 ssh-agent 是否已经在 bash 中运行 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:51:11.047000             🧑  作者: Mango

代码示例2
if [ $(ps ax | grep [s]sh-agent | wc -l) -gt 0 ] ; then
    echo "ssh-agent is already running"
else
    eval $(ssh-agent -s)
    if [ "$(ssh-add -l)" == "The agent has no identities." ] ; then
        ssh-add ~/.ssh/id_rsa
    fi

    # Don't leave extra agents around: kill it on exit. You may not want this part.
    trap "ssh-agent -k" exit
fi