Back to lessons

Cybersecurity Triage

Risk: safe

List Accounts with Login Shells

You need to separate human or interactive accounts from service accounts in a passwd-style file.

Command

awk -F: '$7 ~ /(bash|sh|zsh)$/ {printf "%s %s\n", $1, $7}' fixtures/user-access-audit/etc/passwd

Before you run this

Risk: safe. Do not disable accounts from this list alone; confirm ownership, automation, and operational purpose first.

Expected output

Usernames and login shells for accounts that can start an interactive shell.

System impact

Nothing changes. The command reads a fixture-local passwd stub and prints accounts with shell-like login programs.

Recovery / rollback: no state is changed.

When to use it

Use during server handoff, user access reviews, and first-response checks before changing accounts.

When not to use it

Do not disable accounts from this list alone; confirm ownership, automation, and operational purpose first.

Watch this command run

Example output from a temporary Linux lab

This example uses disposable sample files and sanitized output so you can inspect the shape of the result before touching a real system.

demo@lab:~$

$ sed -n '1,8p' sample-files/user-access-audit/etc/passwd

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
alex:x:1000:1000:Alex Admin:/srv/example/users/alex:/bin/bash
deploy:x:1001:1001:Deploy Bot:/srv/example/users/deploy:/bin/bash
reports:x:1002:1002:Reports Service:/srv/example/users/reports:/usr/sbin/nologin
breakglass:x:1003:1003:Break Glass:/srv/example/users/breakglass:/bin/bash
backup:x:1004:1004:Backup Service:/srv/backup:/usr/sbin/nologin

$ awk -F: '$7 ~ /(bash|sh|zsh)$/ {printf "%s %s\n", $1, $7}' sample-files/user-access-audit/etc/passwd

root /bin/bash
alex /bin/bash
deploy /bin/bash
breakglass /bin/bash
View reproducible demo details

This page shows the sanitized shell transcript and the setup steps needed to reproduce the example.

Lab setup steps

  1. sed -n '1,8p' fixtures/user-access-audit/etc/passwd
  2. awk -F: '$7 ~ /(bash|sh|zsh)$/ {printf "%s %s\n", $1, $7}' fixtures/user-access-audit/etc/passwd

next steps

Related commands

Cybersecurity Triage Risk: safe

Find SSH Keys for nologin Users

A nologin shell does not automatically mean SSH keys are irrelevant.

comm -12 <(awk -F: '$7 !~ /(bash|sh|zsh)$/ {print $1}' fixtures/user-access-audit/etc/passwd | sort) <(find fixtures/user-access-audit/home -path '*/.ssh/authorized_keys' -printf '%h\n' | awk -F/ '{print $(NF-1)}' | sort)
Cybersecurity Triage Risk: safe

Find SSH Key Users with sudo

The highest-priority access review starts where SSH keys and sudo overlap.

comm -12 <(find fixtures/user-access-audit/home -path '*/.ssh/authorized_keys' -printf '%h\n' | awk -F/ '{print $(NF-1)}' | sort) <(awk -F: '$1=="sudo" {gsub(",","\n",$4); print $4}' fixtures/user-access-audit/etc/group | sort)
Cybersecurity Triage Risk: safe

List Users with Login Shells

Not every local account should be able to log in.

awk -F: '$7 ~ /sh$/ {print $1, $7}' etc/passwd
Cybersecurity Triage Risk: safe

List Privileged Group Members

Group membership can grant more access than the username suggests.

awk -F: '$1 ~ /^(sudo|adm|docker)$/ && $4 != "" {print $1 ": " $4}' fixtures/user-access-audit/etc/group
Cybersecurity Triage Risk: safe

Find Password-Enabled Accounts

A shell account with an unlocked password hash deserves extra attention.

awk -F: '$2 !~ /^(!|\*)/ {print $1}' fixtures/user-access-audit/etc/shadow
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • lpic1:103-gnu-unix-commands
  • lpic1:110-security
  • lfcs:essential-commands
  • lfcs:security-hygiene
  • linuxplus:automation-scripting
  • linuxplus:provisional
  • risk:read-only

Useful for

  • LPIC-1 style command-line practice
  • LFCS style performance tasks
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.