10

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?

1
  • 1
    FWIW, IMO changing the port adds little to security as all the cracking tools can recognize ssh listening regardless of port. It may quiet the logs a bit, but, IMO, there are better methods of quieting the logs. Also changing the port is a bit of a pain as you then have to configure or specify the port when you connect. If you are the only user perhaps no big deal but if multiple users are connecting it becomes a pain to have to use a different port with every server. I suggest keys and some other tips here - bodhizazen.com/Tutorials/SSH_security
    – Panther
    Sep 22, 2017 at 17:27

2 Answers 2

24

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
3
  • Yes and restart the ssh server or reload the config after the edit.
    – Panther
    Sep 22, 2017 at 17:33
  • 1
    Edited for those who want the complete process, thanks for the suggestion.
    – ob2
    Sep 22, 2017 at 18:19
  • Unit ssh.service not found
    – mrid
    Sep 6, 2018 at 10:33
2

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:

  1. sudo service ssh restart or sudo systemctl restart sshd.service
  2. 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!

1
  • 1
    by default ubuntu is accepts all traffic and if one is using a firewall more likely than not it is ufw. Even if you run that command, it will not be preserved with a reboot. To do that you would need to use iptables-persistent or configure iptables - thomas-krenn.com/en/wiki/…
    – Panther
    Sep 22, 2017 at 17:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .