GoAdmio

installssh

Reinstall the OpenSSH server and client from scratch, open port 22 in the firewall, remove /etc/ssh/sshrc, and reapply GoAdmio's SSH hardening

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


Overview

/go/installssh repairs a broken or untrusted SSH setup by replacing it with a clean one. It:

[!WARNING] Run this from the server console, a VNC or KVM session, or another out-of-band connection, not from SSH. The command removes the SSH server before it installs it again and has no rollback. If the reinstall fails, for example because the package repository is unreachable, the server is left without an SSH server and you can't connect to fix it. See Limitations.

[!WARNING] The command resets SSH to a clean state. Custom settings in sshd_config, such as a changed port, are not kept, and on Debian and Ubuntu the server's SSH host keys are typically deleted too. See What gets reset.


Quick start

# Reinstall SSH and reapply GoAdmio's hardening
/go/installssh

Then check that the service is running and listening:

sshd -t && ss -ltnp | grep sshd

Syntax

/go/installssh

Run it as root. Most steps use sudo, but the dpkg and apt commands on Debian and Ubuntu run without it.


Options

None. Any arguments you pass are written to the log file and otherwise ignored.


Output

The command prints the output of the package manager (dnf or apt), the firewall tool, and finally ssh. It doesn't print a success message and doesn't stop on errors: every step runs even if an earlier one failed. The exit status is that of the last command, /go/ssh.

Every run adds a line to /var/log/go/installssh.log:

[Nov 20 14:03:11]# installssh

Examples

# Run the reinstall
/go/installssh
# Check the service (RHEL family)
systemctl status sshd
# Check the service (Debian and Ubuntu)
systemctl status ssh
# Test the SSH configuration for errors
sshd -t
# Check that the server is listening on port 22
ss -ltnp | grep sshd
# Check the firewall rule (RHEL family)
firewall-cmd --permanent --list-ports
firewall-cmd --list-ports
# Check the firewall rule (Debian and Ubuntu)
ufw status
# Show the fingerprint of the host key now in use
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
# On a client: forget the old host key after the server's keys changed
ssh-keygen -R server.example.com
# Review past runs
tail /var/log/go/installssh.log

Troubleshooting

Symptom Likely cause Fix
You can't connect over SSH after the command The reinstall failed, the service isn't running, or the port is blocked. Log in at the console. Install openssh-server again, start the service, and check the firewall.
dnf or apt errors, or the package isn't found The repositories or the network are unavailable. Fix the network or repository settings at the console, then run the command again.
REMOTE HOST IDENTIFICATION HAS CHANGED on the client New host keys were generated, so the server no longer matches the key the client saved. Check the new fingerprint at the console, then run ssh-keygen -R <host> on the client.
Port 22 is still blocked on the RHEL family The rule was added with --permanent but firewalld wasn't reloaded. Run firewall-cmd --reload.
firewall-cmd: command not found or FirewallD is not running firewalld isn't installed or isn't running. Start it, or open the port with allow or firewall.
ufw allow says Skipping adding existing rule The ssh and 22/tcp rules are the same. Nothing. The message is harmless.
UFW shows the rules but port 22 is still closed UFW is inactive, so its rules aren't enforced. Check which firewall is in use with firewall. The command doesn't enable UFW.
SSH no longer uses your custom port sshd_config was reset and rewritten by ssh. Set the port again with port. The firewall step opens only port 22.
sshd isn't running on the RHEL family The command doesn't start or enable the service explicitly. Run systemctl enable --now sshd.
Other packages were removed -y lets the package manager remove packages that depend on OpenSSH. Review dnf history or /var/log/apt/history.log and reinstall them.
The command did nothing for SSH packages The value in /usr/local/goadmio/linux/os.db isn't an exact match for a supported system. Check the file. It must contain exactly one of the names in Supported systems.

Details

Supported systems

The command reads the operating system name from /usr/local/goadmio/linux/os.db and requires an exact match.

Family Names matched Package manager Firewall step
RHEL family AlmaLinux, Rocky, CentOS, Red Hat, Fedora dnf firewall-cmd: adds port 22/tcp to the public zone, permanently
Debian family Debian, Ubuntu apt ufw: allow ssh and allow 22/tcp

On any other value, the package and firewall steps are skipped, but the command still deletes /etc/ssh/sshrc and runs ssh.

What it does

Family Steps
RHEL family Removes openssh-server and openssh-clients, installs both again, and adds the firewall rule.
Debian family Runs dpkg --configure -a. Purges and removes openssh-server and openssh-client, installs both again non-interactively, and adds the firewall rules.
All systems Deletes /etc/ssh/sshrc and runs /go/ssh.
flowchart TD
    A["installssh"] --> B["Log the run"]
    B --> C{"OS in os.db"}
    C -- "RHEL family" --> D["dnf remove and install openssh-server and openssh-clients"]
    D --> E["firewall-cmd add port 22 (permanent)"]
    C -- "Debian family" --> F["dpkg --configure -a"]
    F --> G["apt purge, remove, install openssh-server and openssh-client"]
    G --> H["ufw allow ssh and 22/tcp"]
    C -- "Other" --> I["Skip packages and firewall"]
    E --> J["Delete /etc/ssh/sshrc"]
    H --> J
    I --> J
    J --> K["Run /go/ssh to rewrite sshd_config"]

What gets reset

Item Result
sshd_config Replaced by the package default, then rewritten by ssh. Custom settings are lost. On the RHEL family, a modified file is typically saved as sshd_config.rpmsave when the package is removed.
SSH port Back to the default, unless ssh restores it. Only port 22 is opened in the firewall.
Host keys On Debian and Ubuntu, purging the server package typically deletes them, and new ones are generated on install. Clients then show a host key warning.
/etc/ssh/sshrc Deleted. This file runs for every SSH login, so removing it also clears any unwanted login hook placed there. Per-user ~/.ssh/rc files are not touched.

Limitations

No rollback

The command removes the SSH server first and has no check that the reinstall worked. A failed download or repository error leaves the server without SSH. That is why you should run it from the console.

Firewall rules and services

Dependent packages

The commands use -y, so the package manager removes any package that depends on the OpenSSH packages without asking. On Debian and Ubuntu this can include metapackages.


See also

Command Description
ssh Rewrite /etc/ssh/sshd_config with GoAdmio hardening
port Change the default SSH port (22) to another port
permitrootlogin Allow root SSH login from a specific IP
dropbear Install Dropbear (a lightweight SSH server) on a custom port
fail2ban Install and configure Fail2ban to ban brute-force sources against SSH, FTP, SMTP, and Dovecot
sshtop Report the top SSH brute-force sources and optionally block them
firewall Install and configure the server firewall with GoAdmio's default open ports
allow Open a TCP port in the server firewall
checkfirewall Check that ports 80, 443, 21, and 22 are open in the server firewall