I am trying to create a shell script that will automatically scp using my private key, a port of my choosing and to a commonly used user account (not my own account). I was able to accomplish this for ssh by doing the following.


ssh -p (port#) <port #> -i ~/.ssh/.id_dsa  -o StrictHostKeyChecking=no -l admin $@

For scp I have the following so far.


scp -P (port#) -i ~/.ssh/.id_dsa  $1   admin $@

If I try running my command without specifying the username I get the following.

user:~$ scputil <file to transfer> host:/tmp
user@'s password:

As you can see it is asking for the password of my user when I was hoping it would use admin.

If I specify the user along with my command it works as I would expect

user:~$ scputil <file to transfer> admin@
<file to transfer>                                          22%   78MB  13.1MB/s   00:20 ETA

Does anyone know of a way to specify the user for the file transfer within the shell script?

Thanks in advance!


In scp you can use the -o option to pass ssh options, used to log in for the file transfer.

So, if you want to make scp log in as admin, use User=admin

so your scp command would become something like

scp -o User=admin -P port -i public_key $@

  • I reread your question and corrected my answer – Nick Sillito Aug 31 '16 at 18:38
  • Thank you! I was not sure of the syntax with the -o option. – CSmith Sep 1 '16 at 1:56

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.