According to IOS documentation*, you can initialize an SSH session from a switch/router and indicate the remote port to connect to, ex. ssh -p 22222

SCP, however, doesn't seem to have that flexibility. copy doesn't allow any connection-specific flags, nor is there an option to add any after entering the scp address. This is a bit of an inconvenience when the remote host doesn't use the default SSH port.

I'm 99% certain that this is a "well that's obviously your answer" situation, but it's worth a shot. Are there any "deeper" commands that "unlock" the ability to specify the remote host's SCP/SSH port?


To help clarify, I'm referring to invoking scp from the switch to the remote host. So on the switch/router you would be typing copy scp:remote local or copy local scp:remote

*(Should it matter, I'm mostly using 2960, 3750(X), 3850, 4506/4507, and 6509)

  • 2
    I strongly recommend against using non-standard ssh ports, this does not do anything in the way of security and makes your devices vulnerable to other types of attacks. Save yourself some time and change it back to default. Aug 13 '16 at 0:59
  • @brian-winning-jr Unfortunately it's not my server (it belongs to our engineering team) but I agree that changing the ports does nothing to "improve" security. The newest member of the engineering team is pushing to change it back to default so that scp will work properly when trying to transfer from IOS CLI Aug 15 '16 at 18:55
  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
    – Ron Maupin
    Aug 11 '17 at 15:09

This wasn’t possible to perform from the switch/router

  • It should be possible to use SCP from a remote host to transfer files between the switch and whatever host the file needs to go to using: scp -3 ${SWITCH_HOSTNAME}:file ${REMOTE_HOST}:file May 30 '18 at 21:08

Yes, it is possible to specify a remote port. On your the localhost you can use the SSH config. You can also do it like this:

$ man scp
    -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
$ scp -P 6969 /path/to/files.tgz user@remotehost:/path/to/drop/file/at

I would suggest using rsync over scp though, and you can specify the port with rsync as well:

   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]

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.