Can not change ssh port | Server 16.04
I want to change the ssh port from 22 to 2800. I tried to change the /etc/ssh/ssh_config
and removed the # from Port line and changed the number to 2800. after trigger the command: service ssh restart
The connection continued. When I tried to connect from the port 2800, It refused.
The Content of /etc/ssh/ssh_config
is: Removed commented lines
Host *
Port 2800
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no
The command service ssh status
gives the following output:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2017-09-22 20:31:45 IRST; 1s ago
Main PID: 1825 (sshd)
Tasks: 1
Memory: 724.0K
CPU: 5ms
CGroup: /system.slice/ssh.service
└─1825 /usr/sbin/sshd -D
Sep 22 20:31:45 GoodMind systemd[1]: Starting OpenBSD Secure Shell server...
Sep 22 20:31:45 GoodMind sshd[1825]: Server listening on 0.0.0.0 port 22.
Sep 22 20:31:45 GoodMind sshd[1825]: Server listening on :: port 22.
Sep 22 20:31:45 GoodMind systemd[1]: Started OpenBSD Secure Shell server.
I tried other ports too. But still it has the same status. What do I do wrong?
Change the port not in the file:
/etc/ssh/ssh_config
but in /etc/ssh/sshd_config
(file with d
letter, meaning "daemon")
Just edit this change and change uncomment and update the line
#Port 22
Don't forget to restart your service as you done it with
service ssh restart
Your settings are correct but you changed them in the wrong config file. It should be /etc/ssh/sshd_config
and you might want to restart the SSH service and open the new port your SSH Server is listening on.
To do this, run the following commands:
-
sudo service ssh restart
orsudo systemctl restart sshd.service
- Open the port on your firewall
sudo iptables -I INPUT -p tcp --dport 2800 -j ACCEPT
.
This should be all you need to accept connections on port 2800
. You can also check what ports your machine is listening on with netstat -lt4
and you should see a line similar to
tcp 0 0 *:2800 *:* LISTEN
Let me know if it works for you!