Review a simplified SSH configuration
Apply an explicit first-value policy to a supplied configuration excerpt.
A text search is not an effective configuration
A line saying PasswordAuthentication no may be a comment, overridden in another context, or irrelevant to a particular connection. Real OpenSSH configuration includes conditional Match blocks, Include files and defaults. Review an effective export from an authorised host when making a real decision.
This exercise uses a deliberately restricted, global excerpt: blank lines, full-line comments and two whitespace-separated fields per directive. There are no conditional blocks, includes or inline comments. Within this format, the first value for a case-insensitive key wins. That contract lets us practise a small parser without claiming to implement OpenSSH.
Missing is a separate state
The review policy wants explicit no values for both PermitRootLogin and PasswordAuthentication. A missing key is reported as missing, not guessed from an assumed default. Any other supplied value needs review. This is a teaching policy, not universal advice for every authentication deployment.
Lowercase keys and values as they enter the lookup. Keep the first observed value with an array-membership test, then print the two requested settings in a fixed order. Treat the file as data; sourcing it would run shell syntax and would not parse SSH configuration correctly anyway.
awk 'NF && $1!~/^#/ {printf "key=%s value=%s\n",tolower($1),tolower($2)}' sshd_excerpt.conf
Put it into practice.
Parse sshd_excerpt.conf using the restricted format described above. Ignore blank lines and full-line comments. Keys and values are case insensitive; the first occurrence of a key wins. Print setting<TAB>observed<TAB>review followed by passwordauthentication then permitrootlogin. Observed is the lowercase value or missing. Review is ok only for explicit no; otherwise review. Ignore unrelated keys.
See an explained solution
awk 'NF && $1!~/^#/ {key=tolower($1);if(!(key in value)) value[key]=tolower($2)}
END {print "setting\tobserved\treview";keys[1]="passwordauthentication";keys[2]="permitrootlogin";for(i=1;i<=2;i++){key=keys[i];v=(key in value)?value[key]:"missing";printf "%s\t%s\t%s\n",key,v,(v=="no"?"ok":"review")}}
' sshd_excerpt.conf
The parser implements the declared first-value rule instead of accidentally letting a later line overwrite it. Explicit missing values distinguish an absent directive from a reviewed, compliant setting.