GoAdmio

port

Change the port the SSH server listens on, open the new port in the firewall, and save it in GoAdmio

On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · Risks · See also


Overview

SSH listens on port 22 by default, and attackers try that port first. Moving SSH to another port cuts down on automatic login attempts. /go/port does this in one command. It:

To go back to the standard port, run /go/port 22.

[!WARNING] Keep your current SSH session open until you have logged in on the new port from a second window. If the new port does not work, the open session is how you fix it. See Risks.


Quick start

# Move SSH to port 2222
/go/port 2222

# Then, from a second terminal, test it before you close the first
ssh -p 2222 root@your-server

Syntax

/go/port <port>

The command writes the call and a timestamp to /var/log/go/port.log. Run it as root.


Arguments

Position Argument Required Notes
1 <port> Yes The new SSH port. Use a free port number above 1024, for example 2222. Use 22 to go back to the standard port.

The port is not validated. Always pass a number from 1 to 65535. With no argument, or with text, an invalid Port line is written and SSH may not start again.

If another program already listens on the port, the command prints Port <port> in use. and stops with status 1. Port 22 is always accepted.


Output

OpenSSH Port has been changed successfully.

This line is printed even if the SSH server did not restart. Check the result with:

sudo ss -tlnp | grep sshd

If the port is already in use:

Port 2222 in use.

Examples

# Move SSH to port 2222
/go/port 2222
# Check which port SSH is listening on
sudo ss -tlnp | grep sshd
# Log in on the new port
ssh -p 2222 root@your-server
# Go back to the standard port
/go/port 22
# Close the old port in the firewall, once the new one works
/go/deny 22

Troubleshooting

Symptom Likely cause Fix
Port <port> in use. Another program uses the port. Choose a different port. List used ports with sudo ss -tulpn.
You cannot connect on the new port The firewall does not allow it yet, or your hosting provider's firewall (such as a cloud security group) blocks it. Check sudo ufw status or sudo firewall-cmd --list-ports. Open the port in the provider's panel too.
You cannot connect, and SSH is not running The new configuration is invalid, for example because of an empty or bad port. In your open session, run sudo sshd -t, fix /etc/ssh/sshd_config, then restart SSH. Without a session, use the server's console.
SSH still listens on port 22 (Ubuntu 24.04 and later) SSH is started by a systemd socket that has its own port setting. Change the port in ssh.socket, or switch SSH to start without the socket.
SSH fails to bind to the new port (AlmaLinux, Rocky, CentOS, Red Hat, Fedora) SELinux only allows SSH on its standard ports. Allow the port with semanage port -a -t ssh_port_t -p tcp <port>.
The old port is still open in the firewall The command opens the new port but does not close the old one. Use deny for the old port, after the new one works.
netstat: command not found net-tools is not installed, so the "in use" check finds nothing. Install net-tools.
The port is not opened in the firewall screen is not installed, so allow could not run in the background. Install screen, then run /go/allow <port>.
Other GoAdmio commands cannot reach this server They use port 22 unless told otherwise. Pass the new port where the command accepts one, for example in smtpsync.

Details

What it does

  1. Records the call in /var/log/go/port.log.
  2. Saves the list of listening ports in /usr/local/goadmio/tmp/ports.db. If the port is on that list, and it is not 22, prints Port <port> in use. and stops.
  3. Deletes every line that starts with Port from /etc/ssh/sshd_config.
  4. Adds Port <port> as the first line of the file.
  5. Opens the port in the firewall, in the background (allow <port>, in a detached screen).
  6. Saves the port as SSHPort in /var/lib/sqlite/config.db.
  7. Restarts the SSH server (sshd).
  8. Prints the confirmation.
flowchart TD
    A["port N"] --> B{"Port in use, and not 22?"}
    B -- "Yes" --> X["Print Port in use, exit 1"]
    B -- "No" --> C["Replace the Port line in sshd_config"]
    C --> D["Open the port with allow, in the background"]
    D --> E["Save SSHPort in GoAdmio"]
    E --> F["Restart sshd"]
    F --> G["Print confirmation"]

How it works with ssh

ssh rebuilds the whole SSH configuration from GoAdmio's settings. Because port saves the new port in those settings, later runs of ssh keep it. A value of 0 or 22 means the standard port.

What is not changed

Item State
The old port in the firewall Stays open.
A firewall at your hosting provider Not touched.
Programs and tools that connect to port 22 Must be told the new port.

Risks


See also

Command Description
ssh Rebuild /etc/ssh/sshd_config and restart the SSH server
allow Open a TCP port in the server firewall
deny Close a TCP port by removing its allow rule from the server's firewall
firewall Install and configure the server firewall
permitrootlogin Allow root SSH login from a specific IP
installssh Reinstall and enable the OpenSSH server
dropbear Install Dropbear (a lightweight SSH server) on a custom port
sshtop Report the top SSH brute-force sources and optionally block them
fail2ban Install and configure Fail2ban to ban brute-force sources