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 to ssh-agent is stored in environment variable SSH_AUTH_SOCK (echo $SSH_AUTH_SOCK) and this variable is not preserved during the sudo so there are two possibilities:

    • Do not use sudo to scp. Run just scp to some sane location and then sudo 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.