ssh-agent子进程中的几个命令
Several commands in the ssh-agent subprocess
我想临时给 ssh-agent
添加一个自定义键,执行一些命令然后忘记它。
手册页说明如下:
ssh-agent [-c | -s] [-d] [-a bind_address] [-t life] [command [arg ...]]
If a commandline is given, this is executed as a subprocess of the agent. When the command dies, so does the agent.
测试表明它确实适用于一个命令:
# 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;
有办法吗?
将两个(或更多)命令包装在一个 bash 命令中,如下所示:
ssh-agent bash -c "ssh-add user_rsa_key; ssh-add -l"
(或者可能将它们放在脚本中)。
我想临时给 ssh-agent
添加一个自定义键,执行一些命令然后忘记它。
手册页说明如下:
ssh-agent [-c | -s] [-d] [-a bind_address] [-t life] [command [arg ...]]
If a commandline is given, this is executed as a subprocess of the agent. When the command dies, so does the agent.
测试表明它确实适用于一个命令:
# 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;
有办法吗?
将两个(或更多)命令包装在一个 bash 命令中,如下所示:
ssh-agent bash -c "ssh-add user_rsa_key; ssh-add -l"
(或者可能将它们放在脚本中)。