I want temporarily add a custom key to the ssh-agent
, execute few commands and forget about it.
Man page states the following:
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.
Tests showed that it indeed work well with one command:
# ssh-agent ssh-add user_rsa_key
Identity added: user_rsa_key (user_rsa_key)
But not with the multiple commands:
# 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;
Is there a way?
Wrap the two (or more) commands inside one bash command like this:
ssh-agent bash -c "ssh-add user_rsa_key; ssh-add -l"
(or possibly put them in a script).