How do I copy files from my local to some remote server which hosts ssh on port other than default (22).

I usually connect to the server using

ssh [email protected] -p 2000

Now I need to copy files with scp

user@localbox:~$ scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/id_rsa_localbox.pub -p 2000

But this does not work.

  • sshfs is also an option :)
    – user323419
    Commented Feb 3, 2016 at 0:05

3 Answers 3


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 [email protected]:~/.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 [email protected]'
  • // , Is there a way to search through the man pages for stuff like this? Commented Aug 26, 2015 at 0:00

use a capital P

(it's in the man page...)


You can create file ~/.ssh/config and put relevant information for the remote host in there:

Host remotehost.com
Port 2000
User username

See man page for ssh_config.

This allows you to then run ssh as:

ssh remotehost.com

and scp as:

scp important_file remotehost.com:

You must log in to answer this question.

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