Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  26] [ 0]  / answers: 1 / hits: 39024  / 3 Years ago, mon, june 28, 2021, 5:19:37

A ssh server on 192.168.1.45 listens on port 2222. I know I can just add -p2222 or add an alias in ~/.bash_aliases, but is there a way to force a certain port when I ssh a specified IP?


More From » ssh

 Answers
2

Sure, you can put these settings in ~/.ssh/config.



Host 192.168.1.45
Port 2222


You can take this opportunity to give the machine a nickname, and set other options, in particular the remote user name. For example, the following declaration makes ssh foo equivalent to ssh -p 2222 [email protected] (Host foo means that the following options apply when you run ssh foo, and the HostName directive makes foo a nickname for 192.168.1.45 with all the other options):



Host foo
HostName 192.168.1.45
Port 2222
User matt

[#41992] Wednesday, June 30, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bleger

Total Points: 468
Total Questions: 108
Total Answers: 100

Location: Belarus
Member since Wed, Dec 7, 2022
1 Year ago
;