I am on Ubuntu 22.10 and I cannot change SSH default port. I have tried the following:
Edited
/etc/ssh/sshd_config, left the default#Port 22line but addedPort 1234below it.Then added allow rule for it in UFW using the command:
sudo ufw allow 1234which added:
To Action From 1234 ALLOW Anywhere 1234 (v6) ALLOW Anywhere (v6)
I then restarted the SSH service using 2 different methods (see start of block below), but I saw no change. Service status states it started listening on port 22 and to verify this I checked the listening ports and sure enough it's still 22.
$ sudo systemctl restart ssh
$ sudo service ssh restart
$ systemctl status ssh
ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; disabled; preset: enabled)
Drop-In: /etc/systemd/system/ssh.service.d
└─00-socket.conf
Active: active (running) since Mon 2022-11-07 10:12:52 AEDT; 5s ago
TriggeredBy: ● ssh.socket
Docs: man:sshd(8)
man:sshd_config(5)
Process: 54858 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 54859 (sshd)
Tasks: 1 (limit: 1020)
Memory: 1.3M
CPU: 13ms
CGroup: /system.slice/ssh.service
└─54859 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Nov 07 10:12:52 webserver.abc.com systemd[1]: Starting OpenBSD Secure Shell server...
Nov 07 10:12:52 webserver.abc.com sshd[54859]: Server listening on :: port 22.
Nov 07 10:12:52 webserver.abc.com systemd[1]: Started OpenBSD Secure Shell server.
ss -tlpn
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 :22 *: -
Am I missing a step or doing something wrong? I do note the service status has preset: enabled, but multiple guides I've read haven't mentioned anything about disabling anything like presets.
EDIT:
Thanks matigo for reminding me, but sshd.service doesn't seem to be installed yet. I have the config files and can remote in just fine, not sure if I just don't understand and I need to install sshd for it to take over the default SSH operations?
sshrather thansshd? Generally the server is restarted withservice sshd restartif you are using the standard server for Ubuntu – matigo Nov 06 '22 at 23:38systemctl list-units --type=serviceI only see one entry for ssh:ssh.service loaded active running OpenBSD Secure Shell serverDo I need to install sshd separately? I thought of this but then thought it strange that I have sshd config files and I can ssh in just fine at the moment using defaults.
When trying to do anything with sshd it suggests it doesn't exist:
– Silently Nov 07 '22 at 00:18Unit sshd.service could not be found.openssh-client/kinetic,now 1:9.0p1-1ubuntu7 amd64 [installed]openssh-server/kinetic,now 1:9.0p1-1ubuntu7 amd64 [installed]– Silently Nov 07 '22 at 00:37