scp --help
or man scp
would have told you the option was -P port
. You also need to declare this before the file arguments:
scp -P 2000 -i ~/.ssh/id_rsa.pub user@remotebox.remotedomain.tld:~/.ssh/id_rsa_localbox.pub
I also wouldn't trust ~
-relative links. Use full paths if you can.
But if you're copying IDs, ssh-copy-id
also has an option to provide SSH connection options:
ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 2000 user@remotebox.remotedomain.tld'
You can use ~/.ssh/config
to specify the ports to use for the hosts (and for setting many other nice things; check the man page man ssh_config
):
# ~/.ssh/config
Host 67.12.21.133
Port 6774
Host 67.129.242.40
Port 6774
When doing this, you have to use the option -3
to scp, which copies the files through your local machine. Otherwise, scp issues the scp command via ssh on the first host, so it actually runs
ssh -p 6774 denny@67.12.21.133 scp -rp /home/denny/testapp1.txt denny@67.129.242.40:
and then the ~/.ssh/config of the first remote host (67.12.21.133) is used instead of your local one.
When you have setup your ~/.ssh/config
correctly, this should work:
scp -rp3 denny@67.12.21.133:/home/denny/testapp1.txt denny@67.129.242.40:
Of course, you can also copy the contents of the ~/.ssh/config file onto your first remote host, and then you can use scp without the -3
option, which will probably speeden up the transfer.
Or you can use the trick that scp uses and use such a command line:
ssh -p 6774 denny@67.12.21.133 scp -rp -P 6774 /home/denny/testapp1.txt denny@67.129.242.40:
(Note the different case of the port parameter for ssh and scp: ssh -p 6774
vs. scp -P 6774
)
PS: I got this information from the OpenSSH bugzilla where I entered this as a bug: https://bugzilla.mindrot.org/show_bug.cgi?id=2020
Best Answer
Try
Where -P stands for port number.