nerdexam
CompTIA

XK0-005 · Question #828

A systems administrator needs to disable root login for SSH. Which of the following commands should the administrator use?

The correct answer is B. sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config. To disable root login over SSH, the PermitRootLogin directive in /etc/ssh/sshd_config must be changed from 'yes' to 'no'.

Security

Question

A systems administrator needs to disable root login for SSH. Which of the following commands should the administrator use?

Options

  • Atouch /etc/ssh/sshd_config | awk 's/PermitRootLoginX yes/PermitRootLoginX no/'
  • Bsed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
  • Ctouch /etc/ssh/sshd_config | print* 1PermitRootLogin/PermitRootLogin no/'
  • Dcat /etc/ssh/sshd_config | grep 's/PermitRootLogin yes/PermitRootLogin no/'

How the community answered

(29 responses)
  • A
    17% (5)
  • B
    72% (21)
  • C
    7% (2)
  • D
    3% (1)

Why each option

To disable root login over SSH, the PermitRootLogin directive in /etc/ssh/sshd_config must be changed from 'yes' to 'no'.

Atouch /etc/ssh/sshd_config | awk 's/PermitRootLoginX yes/PermitRootLoginX no/'

touch creates an empty file or updates its timestamp, and piping its output to awk with this syntax is incorrect for editing file content.

Bsed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_configCorrect

The sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config command uses sed to perform an in-place (-i) substitution (s/old/new/) on the /etc/ssh/sshd_config file. It specifically changes the line PermitRootLogin yes to PermitRootLogin no, thereby disabling direct root login via SSH.

Ctouch /etc/ssh/sshd_config | print* 1PermitRootLogin/PermitRootLogin no/'

touch creates an empty file or updates its timestamp, and the print* 1PermitRootLogin/PermitRootLogin no/' syntax is invalid for modifying file content.

Dcat /etc/ssh/sshd_config | grep 's/PermitRootLogin yes/PermitRootLogin no/'

cat /etc/ssh/sshd_config | grep 's/PermitRootLogin yes/PermitRootLogin no/' would simply display lines matching the pattern and not modify the file.

Concept tested: SSH server configuration using sed

Source: https://man.openbsd.org/sshd_config.5

Topics

#SSH configuration#Security hardening#sed command#Linux file editing

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice