5

I am trying to change the port of SSH on an EC2 instance, but I am not getting this to work.

What I am doing is the following:

Open the file /etc/ssh/ssh_config

Uncomment and change the line Port 2345

Save and close

run the command service sshd restart

Now I can still connect to port 22. And when I run the command ssh -p 2345 localhost i get:

ssh: connect to host localhost port 2345: Connection refused

9

It may be a typo, but if you want to change the port that sshd listens on, you need to edit the Port setting in /etc/ssh/sshd_config, not ssh_config.

Also, you're using two different port numbers above (2345 and 2232), but I'm sure that's a typo.

If it's not that, could you edit into your question the output of iptables -L -n -v so we can see your firewall rules?

  • 1
    Oh i see there are 2 files!! – Saif Bechan Dec 6 '11 at 11:13
  • Yes, because there are two pieces of software. ssh_config controls the behaviour of ssh, that is, your local ssh client. sshd_config controls the behaviour of sshd, that is, your local ssh server. – MadHatter Dec 6 '11 at 11:14
  • 1
    Yeah I was working in the wrong file. Such an idiot. Everything is ok now. – Saif Bechan Dec 6 '11 at 11:15
2

ssh_config is the SSH client configuration file.

sshd_config is the SSH daemon (server) configuration file.

So, if you want to change the port for the ssh server You have to edit the sshd_config file,

Uncomment the line

Port 22

and change port 22 to 2345.

After editing the file, restart the ssh service.

/etc/init.d/sshd restart

And also allow ssh port in the iptables. and restart the iptables.

0

Maybe there is something simple but you have Port 2345 in your config and then try to connect to 2232.

2345 != 2232

  • Oh no that was a mistake, Ill edit that. – Saif Bechan Dec 6 '11 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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