Traditionally ssh runs on port 22, but that does not mean it has to. Where I work each machine that runs ssh runs it on a different port. I do not know why, but it causes quite a bit of fun when trying to use common ssh based commands that all expect ssh to run on the default port. I have had to figure out more then a few of the workarounds and will share them because I had trouble finding a few of them.
SSH
SSH is easy to connect to a non-standard port, simply use the -p flag followed by the port number. Following is an example:
1 |
ssh -p 1000 user@domain.com |
ssh-copy-id
For those who are not aware, you can create an identity file and copy it to the remote machine to allow you to log in without the need of a password (Link to the guide that taught me). ssh-copy-id assumes that the remote machine is running on port 22 and you have to trick it to change the port. We use the same -p flag as with ssh, but we need to put the whole of the arguments into single quotes for it to work. See the example below:
1 |
ssh-copy-id '-p 1000 -i ~/.ssh/id_rsa user@domain.com' |
rsync
rsync has a -e flag for setting which remote shell to use. after the -e flag you put the ssh options like is you were using ssh normally. Be sure to put them inside double quotes or they will get confused with rsync options. See the following example:
1 |
rsync -e "ssh -p 1000" /local/path/ user@domain.com:/remote/path/ |
scp
SCP is very easy, simply use the -P flag to set the port number, like in the following example:
1 |
scp -P 1000 /local/file user@domain.com:/remote/file |