We just got a new router (Vodafone THG3000g) and it doesn't allow port forwarding for port 22. This means I can SSH in locally but can't do it remotely using the public ip.

I should be able to do port forwarding for a different port on the router, but how can I update the SSH settings on my Pi to do set this up? E.g. if i wanted to use port 2222.


  • Type "ssh change port number" into your favorite search tool.
    – Bob Brown
    Mar 26 '20 at 15:43
  • Yep, cheers for that. Was looking for an answer from the community I trust more than google. But well done for bringing the community down.
    – lukenm
    Mar 26 '20 at 16:50
  • 1
    sudo vi /etc/ssh/sshd_config add a line with Port 2222. Save the file and restart the ssh daemon.
    – Dougie
    Mar 26 '20 at 18:26
  • 1
    Although this is not the place for extended debate, "bringing the community down" includes asking a member of said community to take time to personally provide you with an answer to a question that must have been answered thousands of times already online. Hooray! If you have a few spare moments of your own, this might be worth some of them.
    – goldilocks
    Mar 26 '20 at 21:38

If you are looking for a procedure to change the SSH default port to another port number like 2222, check the SSH config file which is located on /etc/ssh/sshd_config.

sudo nano /etc/ssh/sshd_config

So, you would see Port 22 that you can change it to Port 2222. Then, save the file and restart the SSH service:

sudo service ssh restart
  • Thanks. After doing this and checking the status of the ssh service it says it's listening on Port 22 still - does that sound correct?
    – lukenm
    Mar 26 '20 at 17:12
  • @lukenm My pleasure. Unfortunately, no, there was a mistake. Check this link out to find out what has changed. -- You need to configure SSH by /etc/ssh/sshd_config not /etc/ssh/ssh_config.
    – M. Rostami
    Mar 26 '20 at 20:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.