How to connect to server via SSH with different port than 22

20,971

Yes, it's possible to change the port. Just use the option to the right of the address.

putty

Side note: if you're using the command line ssh client, you can specify the port as ssh -p <port> user@server. The port does not appear at the end of the address like it does in other URI schemes.

Edit: it's possible to have SSH configured to use any port that you like, as well as configuring your router to forward incoming ports to any other port. Make sure that you if your DNS record points to your router (somewhere in the DMZ I'm guessing), that you're connecting to the external port that you specified in your router, and that the internal port on the router is configured to the same port as your sshd agent.

Share:
20,971
taiBsu
Author by

taiBsu

by day: full-time C++ developer (currently c++17/boost database back-end programming / template meta-programming) by night: game and graphics programming enthusiast

Updated on September 18, 2022

Comments

  • taiBsu
    taiBsu over 1 year

    First of all, I'm a complete newbie when it comes to network topics.

    I'm using a Banana Pi for Samba, media center and other stuff at my home network. As I have a Hitron router I'm able to use Port Forwarding to access my local network from remote.

    Setting up Port Forwarding at the router I found out that you can enter a different internal port than the external port. Now if I want to access my Banana Pi via SSH, is it possible to connect to it using another port than 22, i.e. 12345, to "hide" the accessibility of port 22 for others, so I just type abcd.efghij.klm:12345 into PuTTY (with my Banana Pi having a DynDNS configuration given of course) which would route to my router's ip at port 22?

  • taiBsu
    taiBsu over 6 years
    I'm sorry, my question seems to be a bit unclear. I'm not asking how to change the port on PuTTY but if it's possible to configure my router to be connected to via port 12345 and forward it to port 22 by itself.
  • Ben Harris
    Ben Harris over 6 years
    @taiBsu that's absolutely possible. It's also possible to configure the SSH agent to listen on a different port as well.
  • taiBsu
    taiBsu over 6 years
    Thanks a lot. Is there anything I will have to pay heed to, i.e. changing any configurations on the Banana Pi?
  • Ben Harris
    Ben Harris over 6 years
    @taiBsu it's really up to you, but the default configuration (usually under /etc/ssh/sshd.config) specifies port 22, so it should be fine as long as the external port defined in your router configs points to the internal port 22.