GoAdmio

permitrootlogin

Allow root SSH login from one IP address or /24 range, or remove the exception with --delete

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


Overview

/go/permitrootlogin lets the root user log in over SSH from an IP address you choose. GoAdmio's hardened SSH configuration restricts root login, so this command adds an exception for a trusted IP address, or for a /24 range, and can remove it again.

It works in two steps:

  1. It saves the IP address in GoAdmio's SSH settings database, as a PermitRootLogin yes setting for that address.
  2. It starts ssh in the background to rebuild /etc/ssh/sshd_config, so the change takes effect.

The command runs sudo internally, so run it as root or as a user with sudo rights. It needs sqlite3, curl, and screen.

[!WARNING] Every address you add can log in as root. Add only addresses you control and trust, and prefer a single static IP over a /24 range, which allows 256 addresses.


Quick start

# Allow root SSH login from one IP address
/go/permitrootlogin 203.0.113.10

Syntax

# Allow an IP address
/go/permitrootlogin <ip>

# Remove an IP address
/go/permitrootlogin <ip> --delete
Form Behavior
/go/permitrootlogin <ip> Allows root login from that address.
/go/permitrootlogin <ip> --delete Removes the exception for that address.

Every run is recorded in /var/log/go/permitrootlogin.log, with the time and the arguments you passed.


Options

Argument Required Default Notes
ip Yes — An IPv4 address, an IPv4 range written as x.x.x.0/24, or an IPv6 address. See Accepted addresses.
--delete No Off Removes the address from the list instead of adding it.

Output

Outcome What you get
Address added IP <ip> added successfully. This IP is now allowed to access the server.
Address removed IP <ip> deleted successfully.
The server's own address Cannot block server IP address. Exit status 1. Nothing is changed.
Not a valid address Invalid IP "<ip>". Exit status 1. Nothing is changed.

The confirmation appears as soon as the database is updated. The SSH configuration is rebuilt in the background afterward, so root login from the address may start working a few seconds later.

The command does not check whether the address was already listed. Adding it again, or removing one that isn't there, still prints the success message.

Log

Each run appends one line to /var/log/go/permitrootlogin.log:

[Nov 21 12:00:00]# permitrootlogin 203.0.113.10

Examples

# Allow a single IPv4 address
/go/permitrootlogin 203.0.113.10
# Allow a whole /24 range
/go/permitrootlogin 203.0.113.0/24
# Allow an IPv6 address
/go/permitrootlogin 2001:db8::1
# Remove an address
/go/permitrootlogin 203.0.113.10 --delete
# List the addresses that are currently allowed
sudo sqlite3 /var/lib/sqlite/ssh.db "SELECT IP, datetime(TimeStamp,'unixepoch') FROM SSH WHERE Directive='PermitRootLogin'"

Troubleshooting

Symptom Likely cause Fix
Cannot block server IP address. You entered this server's own IPv4 or IPv6 address. The wording of the message is misleading: nothing is being blocked. Use the public IP of the computer you connect from.
Invalid IP "<ip>" The value isn't an IPv4 address, an x.x.x.0/24 range, or an IPv6 address. Host names and other range sizes are not accepted. Correct the value and run again.
Root login still fails after the success message The SSH configuration is rebuilt in the background and hasn't finished, or the rebuild failed. Wait a few seconds and try again. Then check the ssh log at /var/log/go/ssh.log.
Root login stopped working from an address that used to work Your public IP address changed (common on home and mobile connections). Add the new address. Remove the old one with --delete.
screen: command not found The screen package isn't installed. Run package, then run the command again.
The database is updated but the SSH configuration isn't The background ssh run didn't start or didn't finish. Run ssh by hand.

Details

Accepted addresses

Type Format Example
IPv4 address Four groups of digits separated by dots 203.0.113.10
IPv4 range Three groups, then .0/24 203.0.113.0/24
IPv6 address Hexadecimal groups separated by colons 2001:db8::1

The check only looks at the shape of the value. It does not test that each IPv4 group is between 0 and 255, so a value such as 999.1.1.1 is accepted. Double-check the address before you run the command. Ranges other than x.x.x.0/24 are rejected.

What it stores

Each added address becomes one row in the SSH table of /var/lib/sqlite/ssh.db:

Column Value
IP The address or range you passed.
Directive PermitRootLogin
Value yes
TimeStamp The time it was added, as a Unix timestamp.

--delete removes the rows for that address. The ssh command uses these settings when it rewrites the SSH configuration.

flowchart TD
    A["permitrootlogin ip [--delete]"] --> B["Log the run, look up the server's IPv4 and IPv6"]
    B --> C{"IP is the server's own address?"}
    C -- "Yes" --> X1["Error, exit 1"]
    C -- "No" --> D{"Valid IPv4, /24 range, or IPv6?"}
    D -- "No" --> X2["Invalid IP, exit 1"]
    D -- "Yes" --> E{"--delete?"}
    E -- "Yes" --> F["Remove the row from the SSH table"]
    E -- "No" --> G["Add the row to the SSH table"]
    F --> H["Start ssh in the background to rebuild sshd_config"]
    G --> H

See also

Command Description
ssh Rewrite /etc/ssh/sshd_config with GoAdmio hardening
port Change the default SSH port (22) to another port
sshtop Report the top SSH brute-force sources and optionally block them
fail2ban Install and configure Fail2ban to ban brute-force sources against SSH, FTP, SMTP, and Dovecot
white Whitelist an IP address on this server and in Cloudflare's firewall for every hosted domain
block Block an IP address in the server firewall and in Cloudflare