Using scp with a forwarded ssh agent
scp
does not support to forward your agent (hardcoded to be disabled in the code) so this is not possible what you are trying.The problem is in
sudo
. Connection tossh-agent
is stored in environment variableSSH_AUTH_SOCK
(echo $SSH_AUTH_SOCK
) and this variable is not preserved during thesudo
so there are two possibilities:Do not use
sudo
toscp
. Run justscp
to some sane location and thensudo cp
the file to the desired location.Force
sudo
to preserve env. variables using the-E
switch:sudo scp -r <new_folder> <second-server-path>
When you want to copy the file between two servers, use
-3
switch, which will make both authentications from your host, where you have access to your agent.