spcurtis81 spcurtis81 - 1 year ago 84
Linux Question

scp to another linux system via ssh where not using port 22

I'm trying to copy a folder from one system to another using scp (secure copy) however I cannot work out how to specify the port.

I understand that to scp, I can...

scp /file/location/folderName user@192.***.*.***:/destination/location/

however I have changed the destination system's SSH port so I get get this error...

ssh: connect to host ..*.*** port 22: Connection refused lost

Is there some sort of -p command I can use to specify port number?

I also tried adding the port like this...

scp /file/location/folderName user@192.***.*.***:>>portNumHere<</destination/location/

Updated with solution...

I was struggling not only with using the wrong -P but also where to place. I know understand and this works for me...

scp -r -P >>portNumHere<< /file/location/folderName user@192.***.*.***:/destination/location/

Answer Source

Use a capital -P port. The lower case -p option conflicts with the -p "preserve" option from cp.

Per the man page:

 scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
     [-l limit] [-o ssh_option] [-P port] [-S program]
     [[user@]host1:]file1 ... [[user@]host2:]file2


 -P port
         Specifies the port to connect to on the remote host.  Note that
         this option is written with a capital ā€˜Pā€™, because -p is
         already reserved for preserving the times and modes of the
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download