mlbaker
Posts: 2
Joined: Tue Oct 08, 2013 4:02 pm

change ssh port

Tue Oct 08, 2013 4:21 pm

Hi all,

I'd like to move ssh to a different port. For some reason I'm having trouble doing this... I ran

Code: Select all

sudo vim.tiny /etc/ssh/ssh_config
and changed this line

Code: Select all

#   Port 22
to this line

Code: Select all

   Port 2122
then I ran the following to restart the ssh service

Code: Select all

sudo service ssh restart
finally I tried to connect to my box on the new port and it does not work. The old port still works. When I run netstat it no changes have taken effect.

Code: Select all

mlbaker@raspberrypi ~ $ netstat -tnl | grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
mlbaker@raspberrypi ~ $ netstat -tnl | grep 2122
I've tried restarting and that does not fix it. I've edited the file again and confirmed that my changes are there. I'm running 2013-09-25-wheezy-raspbian.zip.

Other possibly relevant information. I installed and removed fail2ban. Thank you for any suggestions.

User avatar
rpdom
Posts: 23526
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: change ssh port

Tue Oct 08, 2013 6:36 pm

You need to change /etc/ssh/sshd_config which is the config file for the ssh server, not /etc/ssh_config which is the client config. Then restart ssh.

mlbaker
Posts: 2
Joined: Tue Oct 08, 2013 4:02 pm

Re: change ssh port

Wed Oct 09, 2013 1:58 am

Haha! Changing that file worked. Thank you very much.

anita2r
Posts: 226
Joined: Sun Dec 23, 2012 6:55 pm
Location: Ottawa, Canada

Re: change ssh port

Sun Oct 13, 2013 10:00 pm

Hi,

Just as an aside:
If you change the port in the /etc/ssh/ssh_config file it allows you to connect to remote machines that use a non-standard port without using the -p parameter every time.

I have several machines that have the port set to 666 in their /etc/ssh/sshd_config files
and my laptop which communicates with all of them has the same port number setup in the /etc/ssh/ssh_config file

Now I can just use ssh machinename instead of ssh -p 666 machinename

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: change ssh port

Sun Oct 13, 2013 10:08 pm

Now I can just use ssh machinename instead of ssh -p 666 machinename
All of which means that the OP should change it back in ssh_config, pronto!

Or else ssh will stop working on most sites...
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

anita2r
Posts: 226
Joined: Sun Dec 23, 2012 6:55 pm
Location: Ottawa, Canada

Re: change ssh port

Mon Oct 14, 2013 1:20 pm

All of which means that the OP should change it back in ssh_config, pronto!

Or else ssh will stop working on most sites...
It all depends on your use of ssh.

If you connect to sites using the standard port, more than your own sites using the non-standard port, then of course set it back, but if you only or mainly connect to sites using a non-standard port then changing the port in the local machine's ssh_config is useful.

In the case of the OP, it looks like the change in the ssh_config file was on the remote (ssh host) machine, so unlikely to be a problem.

Regards

confuseling
Posts: 144
Joined: Mon Aug 26, 2013 1:41 pm

Re: change ssh port

Mon Oct 14, 2013 1:31 pm

You can specify it per host, if you like.

http://nerderati.com/2011/03/simplify-y ... nfig-file/
http://forums.debian.net

anita2r
Posts: 226
Joined: Sun Dec 23, 2012 6:55 pm
Location: Ottawa, Canada

Re: change ssh port

Mon Oct 14, 2013 2:40 pm

confuseling - thanks for posting that link - really useful

Return to “Networking and servers”