Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

sshd

The OpenSSH server. Mostly used through systemctl; the command itself tests the configuration (-t, -T) and helps debugging.

Level
RHCSA exam
Group
SSH and remote work
Needs root
Yes
Package
openssh-server

What it does

sshd listens (default port 22) and handles SSH logins. On RHEL it runs as sshd.service. Settings are in /etc/ssh/sshd_config and the drop-in folder /etc/ssh/sshd_config.d/ (first value wins). After a change, test with sshd -t, then systemctl reload sshd.

sshd -T prints the effective settings after all files are read — the best way to check what really applies.

How to write it

sshd [-46DdeGiqTtV] [-C SPEC] [-c CERT] [-E LOG] [-f CONFIG] [-g TIME] [-h KEY] [-o OPTION] [-p PORT]

Main parts

Port N
Listen port.
PermitRootLogin yes|prohibit-password|no|forced-commands-only
How root may log in.
PasswordAuthentication yes|no
Allow passwords.
PubkeyAuthentication yes|no
Allow keys.
AllowUsers, AllowGroups, DenyUsers, DenyGroups
Who may log in.
MaxAuthTries N
Tries per connection.
ClientAliveInterval S, ClientAliveCountMax N
Keepalive and idle timeout.
X11Forwarding, AllowTcpForwarding
Forwarding.
Banner FILE
Text before login.
Match User|Group|Address …
Settings for some users or networks.

Options 19

Most used

-t
Test the config and keys; print errors only.
-T
Test and print the effective config.
-C SPEC
With -T: settings for a connection, like user=lisa,addr=10.0.0.5,host=x.
-G
Print the config (without key checks).
-f FILE
Use another config file.
-o OPTION
Override one setting.
-p PORT
Listen on this port.
-d
Debug mode: one connection, verbose output, no daemon.
-D
Do not detach (systemd runs it like this).
-e
Debug logs to stderr.
-E FILE
Append logs to a file.
-h FILE
Host key file.
-c FILE
Host certificate file.
-g SECONDS
Login grace time.
-i
Run from inetd.
-q
Quiet.
-u LEN
utmp host field length.
-4, -6
IPv4 or IPv6 only.
-V
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Test the config

    sshd -t

    No output = fine. Always run before a reload.

  2. 2Show the effective settings

    sshd -T | grep -iE '^(port|permitrootlogin|passwordauthentication|allowgroups)'
    port 2022
    permitrootlogin no

    What really applies after all files.

  3. 3Settings for one user and address

    sshd -T -C user=lisa,addr=192.168.122.1,host=client | grep -i allowtcp

    Tests Match blocks.

  4. 4Reload after a change

    systemctl reload sshd

    Existing sessions stay.

  5. 5Debug a failing login

    /usr/sbin/sshd -d -p 2222

    One test connection on port 2222 with full debug output: ssh -p 2222 user@host.

  6. 6Status and logs

    systemctl status sshd
    journalctl -u sshd --since -1h

    Failed logins and errors.

  7. 7New port: SELinux and firewall

    semanage port -a -t ssh_port_t -p tcp 2022
    firewall-cmd --add-port=2022/tcp --permanent; firewall-cmd --reload

    Without these, sshd cannot use or expose the port.

  8. 8Different rules for a network

    cat /etc/ssh/sshd_config.d/40-match.conf
    Match Address 192.168.122.0/24
        PasswordAuthentication yes

    Passwords only from the admin network.

  9. 9Host key fingerprints (tell users)

    for k in /etc/ssh/ssh_host_*_key.pub; do ssh-keygen -lf "$k"; done

    Users compare these at the first connection.

  10. 10Audit the SSH config (security)

    sshd -T | grep -E '^(permitrootlogin|passwordauthentication|x11forwarding|maxauthtries|permitemptypasswords)'

    Quick hardening check against your policy.

Files

/etc/ssh/sshd_config
Main config.
/etc/ssh/sshd_config.d/*.conf
Drop-ins (read first; first value wins).
/etc/ssh/ssh_host_*_key
Host keys.
~/.ssh/authorized_keys
Allowed keys per user.

Exit codes

0Config OK (with -t/-T).
255Error.