Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 6 down vote accepted

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?

share|improve this answer
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
Yeah I was working in the wrong file. Such an idiot. Everything is ok now. – Saif Bechan Dec 6 '11 at 11:15

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.

share|improve this answer

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

2345 != 2232

share|improve this answer
Oh no that was a mistake, Ill edit that. – Saif Bechan Dec 6 '11 at 11:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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