0

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.

####!/bin/bash

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

For scp I have the following so far.

####!/bin/bash

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
[email protected]'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> [email protected]:/tmp/
<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!

1

1 Answer 1

0

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 $@

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .