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'.
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)- A17% (5)
- B72% (21)
- C7% (2)
- D3% (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'.
touch creates an empty file or updates its timestamp, and piping its output to awk with this syntax is incorrect for editing file content.
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.
touch creates an empty file or updates its timestamp, and the print* 1PermitRootLogin/PermitRootLogin no/' syntax is invalid for modifying file content.
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
Community Discussion
No community discussion yet for this question.