Linux – Temporary changes to /etc/passwd or /etc/group – how-to

groupslinuxpasswduser-management

I want to temporarily modify /etc/passwd and/or /etc/group to "remove" a user/group without deleting the line.

Is there a way to do that?

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1161913 seems to indicate it may not be supported (but may also be HPUX-specific).

Best Answer

to temporarily lock a user's account you can do passwd -l username which simply adds a '!' to the beginning of the password hash in /etc/shadow, preserving the user's password, and preventing them from being able to log in with any password.