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
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
You also need to change the port inside /etc/ssh/sshd_config, it would be
Port your_port_number