My question is, how do i make the script into a if else statement that it checks if “PermitRootLogin no”, it should display the “Vulnerability: No”
and if the “PermitRootLogin yes” it should display as “Vulnerability: Yes”?
Thanks in advance!
Script
#!/binbash echo "Audit criteria: Root login via SSH are not allowed" echo "Vulnerability: Yes" echo "Details: See below" echo echo "Command:" echo "grep "^PermitRootLogin" /etc/ssh/sshd_config" echo echo "Output:" grep "^PermitRootLogin" /etc/ssh/sshd_config
Advertisement
Answer
you can use variables to store the command output.
This script should do what you need-
#!/binbash permitrootlogin=`grep "^PermitRootLogin" /etc/ssh/sshd_config` if [[ $permitrootlogin == "PermitRootLogin no" ]] then isVulnerability="No" else isVulnerability="Yes" fi echo "Audit criteria: Root login via SSH are not allowed" echo "Vulnerability: $isVulnerability" echo "Details: See below" echo echo "Command:" echo "grep "^PermitRootLogin" /etc/ssh/sshd_config" echo echo "Output:" echo $permitrootlogin