0

How to change the ssh port on Ubuntu 23.04?

root@ubuntu:/home/user# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 23.04
Release:        23.04
Codename:       lunar
guiverc
  • 28,623
  • 5
  • 46
  • 74
  • Please [edit] your question and explain what you want to achieve. If you want/need to use a different port number at your public IP address, you could configure this in the port forwarding of your router. – Bodo Jul 25 '23 at 03:41
  • 4
    Does this answer your question? [SSH default port not changing (Ubuntu 22.10)](https://askubuntu.com/questions/1439461/ssh-default-port-not-changing-ubuntu-22-10) – muru Jul 25 '23 at 03:56

1 Answers1

0

In Ubuntu 22 and mostly in Ubuntu 23 if we change ssh port in sshd_config it doesn't work so I figured it out following method

sudo vim /lib/systemd/system/ssh.socket

Change the following parameter to the port of your choice e.g. 1122

ListenStream=1122

Save the file and quit the vim editor with the command wq! and then execute the following commands one by one

This will reload the daemon

sudo systemctl daemon-reload  

To restart the SSH server

sudo systemctl restart ssh     

and if you want to check the port you can check with the following command netstat -ant |grep 6381

in case you you face the error Command 'netstat' not found

you can be installed with: apt install net-tools -y

muru
  • 193,181
  • 53
  • 473
  • 722