Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

sshd

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

Niveau
RHCSA-examen
Groep
SSH en werken op afstand
Root nodig
Ja
Pakket
openssh-server

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

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.

Zo schrijf je het

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

Belangrijkste delen

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.

Opties 19

Meest gebruikt

-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.

Voorbeelden 10

$ als gewone gebruiker# als root (of met 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.

Bestanden

/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.

Exitcodes

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