System maintenance

optimize_centos7_ssh.sh

Designed for legacy CentOS 7 hosts where SSH login is slow because the daemon waits on reverse DNS lookup, GSSAPI negotiation, or IPv6 fallback. The script backs up sshd_config, enforces the recommended settings, validates the syntax, and then restarts sshd.

One-liner

curl -fsSL helper.sh/optimize_centos7_ssh.sh | sudo bash
curl -fsSL -o optimize_centos7_ssh.sh helper.sh/optimize_centos7_ssh.sh && sudo bash optimize_centos7_ssh.sh

Requirements

  • CentOS 7 or similar OpenSSH host
  • root privileges or sudo
  • /etc/ssh/sshd_config present
  • systemctl or service command

Best for

  • Shorten slow SSH login caused by reverse DNS lookup
  • Disable GSSAPI auth on hosts that do not use Kerberos
  • Standardize SSH latency tuning during CentOS 7 maintenance

Highlights

  • Creates a timestamped backup before editing sshd_config
  • Sets UseDNS no, GSSAPIAuthentication no, and AddressFamily inet idempotently
  • Runs sshd -t before restart so bad config does not get applied blindly

Recommended procedure

  1. Fetch the script from helper.sh with curl.
  2. Run it as root or through sudo.
  3. Let the script back up, update, validate, and restart sshd.
  4. Reconnect with SSH and confirm the login delay is gone.

Safety notes

  • Review the raw script first if the host is production-critical.
  • If the server depends on Kerberos or IPv6-only connectivity, do not apply these defaults blindly.
  • Keep an existing SSH session open while testing the restart.

Scenario article

How to speed up slow SSH login on CentOS 7 before deeper troubleshooting

A practical guide to using optimize_centos7_ssh.sh when an old CentOS 7 host pauses too long before the SSH password prompt because of reverse DNS, GSSAPI, or IPv6 fallback.

Related topics

CentOS 7 maintenance and recovery

Keep legacy CentOS 7 hosts installable and maintainable when yum repositories fail, mirrors expire, or Docker data needs to be moved off a crowded disk.

Open topic

Problem pages

Why is CentOS 7 SSH login so slow

The usual causes are reverse DNS lookup, GSSAPI auth negotiation, and sometimes IPv6 fallback. Disable those waits before doing deeper SSH troubleshooting.

Open page