The Daemon Listening Interface Vector
When operating a headless Ubuntu Linux server, remote administration is strictly executed via the Secure Shell (SSH) protocol. By default, the `sshd` daemon is mathematically hardcoded to listen for incoming TCP packets on Port 22. Because this is a universal standard, Port 22 is relentlessly subjected to automated botnet scans and brute-force password attacks from hostile entities across the global internet within seconds of the server booting. To secure the perimeter, you must instruct the core OS kernel to execute a protocol rewrite, violently severing the daemon’s connection to Port 22 and forcing it to bind to a high, obfuscated port number (e.g., 45022) to evade automated telemetry sweeps.
How to Change SSH Port in Ubuntu
The Linux architecture utilizes the master `/etc/ssh/sshd_config` registry to dictate the exact parameters of the SSH daemon. You must inject a new mathematical port integer into this file and restart the daemon.
1. Open your terminal application and connect to the remote server via SSH (currently on Port 22).
2. Phase 1: The Prerequisite Firewall Override:
* CRITICAL: Before changing the daemon’s port, you must mathematically authorize the new port through the Ubuntu Firewall (UFW). If you fail to do this, the OS will lock you out permanently upon reboot.
* Type exactly (assuming you choose port 45022):
sudo ufw allow 45022/tcp
* Press Enter. The OS will output `Rule added`.
3. Phase 2: Target Acquisition (Editing the Registry):
* You must possess absolute God-level (`sudo`) authority to rewrite the core daemon config.
* Type exactly:
sudo nano /etc/ssh/sshd_config
* Press Enter.
* The terminal UI drops into the stark text editor. Scroll down until you locate the specific row that reads: #Port 22.
4. Phase 3: The Execution Trigger (The Port Rewrite):
* The `#` symbol indicates the line is commented out (inactive). You must physically delete the `#` symbol.
* Delete the integer `22` and inject your new payload: `45022`.
* The line must now read exactly: Port 45022.
* Press Ctrl + O (to save), Enter (to confirm), and Ctrl + X (to exit nano).
5. Phase 4: The Daemon Reinitialization (The Restart):
* The changes are mathematically inert until the daemon is rebooted.
* Type exactly:
sudo systemctl restart sshd
* Press Enter.
* The Mathematical Result: The kernel issues a `SIGTERM` to the daemon and spins up a new instance bound strictly to Port 45022. Do not close your current terminal window yet. Open a new terminal window and test the connection using the `-p` flag: ssh -p 45022 user@server_ip. Only after the new bridge connects successfully should you terminate the legacy session.