Home > Back-end >  ssh-agent doesn't work however eval ssh-add does, why?
ssh-agent doesn't work however eval ssh-add does, why?

Time:12-16

I have 3 servers: (a), (b) and (c).

Server (a) and (c) have server's (b) public key inside authorized_keys file.

I try to access server (c) throughout ssh connection to server (b) from server (a).

(a) ---> (b) ---> (c)

Using:

ssh-agent
ssh -A <command>

Fails! with

Permission denied (publickey)

However using:

eval `ssh-agent`
ssh-add
ssh -A <command>

Succeeds.

What is the problem?

CodePudding user response:

Utility ssh-agent, when run alone, will have no effect at all on private key forwarding, as stated in man page:

If a command (and optional arguments) is given, this is executed as a subprocess of the agent. The agent exits automatically when the command given on the command line terminates

Since you don't provide a command, the subprocess is terminated at the beginning of ssh-agent execution, meaning - no action is performed.

Your solution is to pass command to the ssh-agent like that:

ssh-agent ssh -A <command>
  • Related