4

I have a lot of servers that I changed my port to 2222.

Can I change on my computer the default port for ssh command? Instead of 22 I want to use 2222 as default.

For instance, instead of using ssh root@ip -p 2222

I want to use ssh root@ip only.

And when I need to use port 22 I type ssh root@ip -p 22

1 Answers1

6

Use your favorite editor to modify ~/.ssh/config

nano ~/.ssh/config

and enter

Host *
User root
Port 2222

this would mean, by default, if you tried

ssh remote-host.com

SSH would actually do this

ssh -p 2222 root@remote-host.com

you can, of course, also specify this per host with a special username

Host remote-host1 remote-host2 remote-host3
User jackvanier
Port 2222

these settings can also co-exist

Host remote-host1 remote-host2 remote-host3
User jackvanier
Port 2222

Host *
User root
Port 2222

See also here for some more ideas.

Robert Riedl
  • 4,401