datadan
07-02-2001, 09:55 AM
I want to change the shell for most of my users from bin/passwd to bin/false.
I know how to do this one by one, but is there a statement I can use that will select all users with UID > 1500 and then change shell as I mentioned above?
Thanks,
Craig McPherson
07-02-2001, 07:29 PM
Okay, not to pry into your personal business, but why would you have anyone's shell set to /bin/passwd? The only usefulness I could think of for such a thing would be to allow users to change their passwords without actually having shell access to the system. I've never seen anybody actually doing that, though.
Anyway, about your question.
1. BACK UP YOUR /etc/passwd AND /etc/shadow FILES! Many distros back them up every night, but you should do it now anyway. Make sure the backups are mode 700.
2.
TEMP1='/bin/passwd'
TEMP2='/bin/false'
cat /etc/passwd | sed "s/$TEMP1/$TEMP2/" > /etc/passwd.temp
3. Examine passwd.temp, make sure it looks okay.
4. cp /etc/passwd.temp /etc/passwd
You mentioned only changing users with UIDs greater than 1500. This will affect all users; but if you have users under 1500 who current have their shells set to /bin/passwd, you can either change them back manually (easiest), or if you have a whole lot of them, whip up a somewhat cryptic command involving sed and awk. Or just move everybody above 1500 to a seperate file, run the sed command on that file, then cat it back onto the main passwd file.