keepcalculator

06 Numbers and Powers

CentOS 7 sshd service not found: install and fix

Card No. 06·31234 · Updated · Standard formula, shown below

If you see “sshd service not found� on CentOS 7, the OpenSSH server package is not installed or the service name is wrong. Install it with yum install openssh-server, then start it with systemctl start sshd and enable it with systemctl enable sshd. This article explains the exact steps, common causes, and how to troubleshoot when the service still won’t start.

Why the error happens

On CentOS 7, the SSH server is provided by the openssh-server package. A minimal installation or a container image often omits it. The error “sshd service not found� appears when you run systemctl start sshd or systemctl status sshd and systemd cannot find a unit file named sshd.service. This usually means one of the following:

  • The openssh-server package is not installed.
  • The service unit file is missing or corrupted.
  • The system is using a different service manager (though CentOS 7 uses systemd by default).
  • The package is installed but the unit file was not generated (rare).

Checking whether the package is installed is the first diagnostic step. Run rpm -q openssh-server – if it prints package openssh-server is not installed, that is the cause.

How to install openssh-server on CentOS 7

CentOS 7 uses yum as the package manager. You need root privileges, so use sudo or switch to root with su -.

  1. Update the package index (optional but recommended): sudo yum update
  2. Install the SSH server package: sudo yum install openssh-server
  3. Start the service: sudo systemctl start sshd
  4. Enable it to start at boot: sudo systemctl enable sshd
  5. Check the status: sudo systemctl status sshd

If the installation succeeds but systemctl start sshd still says “service not found,� verify that the unit file exists at /usr/lib/systemd/system/sshd.service. If it is missing, reinstall the package with sudo yum reinstall openssh-server.

How to verify SSH is working

After starting the service, confirm it is listening on port 22 (the default). Use sudo netstat -tulpn | grep :22 or sudo ss -tulpn | grep :22. You should see a line with sshd and 0.0.0.0:22 (or :::22 for IPv6). If not, check the service status for errors.

From another machine, try ssh user@server-ip. If you are testing on the same machine, ssh localhost works. If the connection is refused, the service may not be running, or a firewall is blocking port 22.

Common problems and fixes

Even after installing and starting sshd, you may encounter issues. Here are the most frequent ones:

  • Firewall blocking port 22: CentOS 7 uses firewalld by default. To allow SSH, run sudo firewall-cmd --permanent --add-service=ssh then sudo firewall-cmd --reload. If you use iptables instead, add a rule for port 22.
  • SELinux blocking connections: SELinux is enforcing by default. If you get “Permission deniedâ€� or connection refused, check sudo ausearch -m avc -ts recent. The correct fix is usually to restore contexts: sudo restorecon -Rv /etc/ssh or use sudo setsebool -P ssh_sysadm_login on if needed (only if you know what you are doing).
  • Host keys missing: When starting sshd for the first time, host keys are generated automatically. If they are missing, run sudo ssh-keygen -A to generate all default keys, then restart sshd.
  • Service fails to start: Check the logs with sudo journalctl -u sshd. Common errors include invalid configuration or missing privilege separation directory. Create it if needed: sudo mkdir -p /var/empty/sshd and set permissions to 700.
  • Wrong service name: On some systems, the service may be named sshd.service or ssh.service. On CentOS 7, it is sshd. Run systemctl list-unit-files | grep ssh to see what is available.

Configuration basics

The main configuration file is /etc/ssh/sshd_config. After editing it, always test the syntax with sudo sshd -t before restarting the service. A common mistake is to set PermitRootLogin no and then try to log in as root – you will be denied. If you change the port, remember to update the firewall and SELinux (if enforcing).

To change the port, edit Port 22 to a different number, then restart sshd. You must also add the new port to firewalld: sudo firewall-cmd --permanent --add-port=2222/tcp (replace 2222 with your port). If SELinux is enforcing, you may need to adjust the port type: sudo semanage port -a -t ssh_port_t -p tcp 2222.

Security considerations

When exposing SSH to the internet, follow basic hardening steps:

  • Disable root login: set PermitRootLogin no in sshd_config.
  • Use key-based authentication instead of passwords: generate a key pair with ssh-keygen and copy the public key to ~/.ssh/authorized_keys.
  • Change the default port to reduce automated attacks (though this is security by obscurity).
  • Consider using fail2ban to block repeated failed login attempts.
  • Keep the system updated: sudo yum update regularly.

Always test SSH access from a separate session before closing the current one, especially if you are editing firewall rules or SSH configuration remotely.

Alternatives to OpenSSH

On CentOS 7, OpenSSH is the standard and recommended SSH server. Alternatives like Dropbear exist but are not in the default repositories. If you need a lightweight SSH server for embedded systems, you could compile Dropbear from source, but for most users OpenSSH is the right choice. There is no need to replace it unless you have a very specific reason.

Frequently Asked Questions

Why does systemctl say “Unit sshd.service not found� after installation?

This can happen if the package installation did not complete correctly. Try sudo yum reinstall openssh-server and then run systemctl daemon-reload to refresh systemd. Also verify the unit file exists at /usr/lib/systemd/system/sshd.service.

How do I start sshd temporarily without enabling it at boot?

Run sudo systemctl start sshd. It will run until the system reboots. To enable it permanently, use sudo systemctl enable sshd.

What is the difference between sshd and ssh?

sshd is the SSH daemon (server) that listens for incoming connections. ssh is the client used to connect to other machines. On CentOS 7, the server package is openssh-server and the client is openssh-clients.

Can I install openssh-server without internet access?

Yes, if you have the RPM file or a local repository. Download the openssh-server RPM and its dependencies, then install with sudo yum localinstall openssh-server*.rpm. Alternatively, use a CentOS 7 DVD as a local repository.

Why is sshd not starting after I changed the port?

If you changed the port in sshd_config, make sure the syntax is correct by running sudo sshd -t. Also check that the new port is allowed by firewalld and SELinux. If SELinux is enforcing, you must add the port to the ssh_port_t type.

How do I check if sshd is running?

Use sudo systemctl status sshd – it shows active (running) or inactive (dead). You can also check with pgrep sshd or ss -tulpn | grep :22.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →