4

I'm currently trying to scp a file from one server to another, using an ssh key on my local computer.

this is the command I'm currently using:

sudo scp -r -o "ForwardAgent yes" <new_folder> <second-server-path>

and I've followed this github doc to verify that my ssh agent is being forwarded to the second server's terminal.

-o "ForwardAgent yes" comes from this reference, but does not appear on my man scp reference.

However, after all this, the command still asks for a password (which we are trying to avoid). Any ideas on how to use the ssh forwarding?

  • can you access via ssh to the second server without password ? – Wissam Roujoulah Nov 30 '16 at 14:12
  • I can access the terminal of both servers from my own computer without a password. However, I am running into these issues between copying a file from one server to another @WissamAl-Roujoulah – efong5 Nov 30 '16 at 14:39
  • check the user that you are trying to use on the remote server and make sure that is the same use that you added a ssh key for it when you copy the file – Wissam Roujoulah Nov 30 '16 at 14:41
4
  • 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.

  • "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." according to the man page, there is no -3 option. Only 1,2,4 or 6. – Sacha Vorbeck Sep 5 '18 at 7:56
  • @SachaVorbeck It probably means that you have very old OpenSSH version. Try to update. – Jakuje Sep 5 '18 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.