I'm curious how someone would implement a script to give either /usr/bin/nologin or /bin/false to all non-root system accounts between 1-999 (and any determined uid range, for that matter).

I like to do this regularly on machines (save for rsync and a few other apps), but I do it manually. That is, I type "usermod [username] -s /usr/bin/nologin" repeatedly for each user.

How would you script this?

awk -F: '{ if ($3 < 1000 && $3 != 0) print "chsh -s /bin/false " $1}' /etc/passwd

inspect the output; if content:

awk -F: '{ if ($3 < 1000 && $3 != 0) print "chsh -s /bin/false " $1}' /etc/passwd | sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy