ssh-agent子进程中的几个命令

时间:2016-09-28 09:52:42

标签: bash ssh-agent

我想暂时向ssh-agent添加自定义键,执行一些命令并忘记它。

手册页说明了以下内容:

  

ssh-agent [-c | -s] [-d] [-a bind_address] [-t life] [command [arg ...]]
  如果给出了命令行,则将其作为代理的子进程执行。当命令死亡时,代理也会死亡。

测试显示它确实适用于一个命令:

# ssh-agent ssh-add user_rsa_key
Identity added: user_rsa_key (user_rsa_key)

但不是多个命令:

# ssh-agent { ssh-add user_rsa_key; ssh-add -l; }
-bash: syntax error near unexpected token `}'
# ssh-agent $(ssh-add user_rsa_key; ssh-add -l)
Could not open a connection to your authentication agent.
Could not open a connection to your authentication agent.
SSH_AUTH_SOCK=/tmp/ssh-UQYDpH5Mopk3/agent.25436; export SSH_AUTH_SOCK;
SSH_AGENT_PID=25437; export SSH_AGENT_PID;
echo Agent pid 25437;

有办法吗?

1 个答案:

答案 0 :(得分:2)

将两个(或更多)命令包含在一个bash命令中,如下所示:

.question>p {
 background-color:red;
 border-radius: 1.618em;
 position: relative;
 top: 50%;
 transform: translateY(-50%); 
 margin:0px;
}

(或者可能将它们放在脚本中)。

相关问题