Ubuntu / SSH Ports, Root Login, and NetworkManager Administration Notes
Before changing Ubuntu SSH ports or authentication, identify the active service and socket configuration. These notes cover port changes, exceptional root access, and when nmtui is appropriate; keep a normal administrative account, public-key access, and a recovery console available. For the related conditions and procedure, see Configure OpenSSH and Test Public-Key Authentication.
Check the active configuration first
cat /etc/os-release
systemctl status ssh.socket ssh.service --no-pager
sudo ss -lntp
sudo sshd -T | grep -E "^(port|listenaddress|permitrootlogin|passwordauthentication|authenticationmethods) "
Keep the current SSH connection open and verify console access. Back up /etc/ssh/sshd_config and included files. OpenSSH uses the first obtained value for many settings; inspect sshd -T -C with the real user and source address when Match rules apply. Changing the port does not replace strong authentication or network access restrictions.
Example: move SSH to port 1980
1980 is an example. Choose an unused port and allow the management source through the active host and cloud firewalls first. If UFW is in use, replace the documentation address 192.0.2.10 below with your real management address. For the related conditions and procedure, see Restrict Management and Service Access with UFW.
sudo ufw allow from 192.0.2.10 to any port 1980 proto tcp
Change Port in the effective SSH configuration, accounting for includes and Match precedence instead of appending competing values. Check its syntax before applying it.
Port 1980
sudo sshd -t
If ssh.socket is active, restarting only the service may leave the listening port unchanged. Inspect the generated socket settings used in Ubuntu 24.04 and later. If an explicit override is needed, use sudo systemctl edit ssh.socket for the following drop-in. The empty ListenStream= clears the previous list. Preserve any existing address-specific binding rather than replacing it with this port-only example.
[Socket]
ListenStream=
ListenStream=1980
Apply the following only for the confirmed socket-based configuration. On a service-only system, do not enable a new socket; reload or restart the running ssh.service after validation.
sudo systemctl daemon-reload
sudo systemctl restart ssh.socket ssh.service
sudo ss -lntp
From a separate client, test ssh -p 1980 user@server. Keep the old port rule and current connection until the listener, new login, and sudo all work. On failure, restore only the SSH settings and socket override changed in this task from the console, validate and apply them, and recover access on the original port first.
Ubuntu OpenSSH documentation explains configuration files and validation.
Treat direct root access as an exception
Use a normal account with sudo as the primary administration path. If direct root access is genuinely required, prepare a public key and verify the effective root-specific policy.
PermitRootLogin prohibit-password
PubkeyAuthentication yes
AuthenticationMethods publickey
These values are not an instruction to overwrite an organization’s global authentication policy. Place root-only rules within the existing Match structure while preserving other administrators’ authentication. prohibit-password alone does not exclude every non-password method; inspect AuthenticationMethods when public-key-only access is required. Account state, key-file permissions, and PAM can impose additional restrictions.
PermitRootLogin yes is not a standalone guarantee of password access: password authentication, account locks, and PAM also apply. Do not enable root password access as a routine fix. Validate with sshd -t, sshd -T -C for the real connection conditions, a new key-based connection, and sudo; restore PermitRootLogin no when direct access is no longer needed.
Check the network manager before using nmtui
systemctl is-active NetworkManager systemd-networkd
sudo netplan get
command -v nmtui
nmtui edits NetworkManager connection profiles. Check the network-manager package if the tool is needed, but installing it does not safely migrate an existing Netplan/systemd-networkd configuration. Avoid having two managers control the same interface; decide on the renderer and recovery plan before changing a remote server. For the related conditions and procedure, see Identify Netplan, NetworkManager, and networkd Ownership.




