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
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
, notssh_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?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
and change port 22 to 2345.
After editing the file, restart the ssh service.
And also allow ssh port in the iptables. and restart the iptables.
Maybe there is something simple but you have Port 2345 in your config and then try to connect to 2232.
2345 != 2232