How do I lock a user account in Linux?



  • 🔴 Important Note
    This locks users when using passwords, pam_unix. It does not disallow SSH public key authentication access.

    To lock user testuser's account:

    # /usr/bin/passwd -l testuser
    Locking password for user testuser.
    passwd: Success
    

    or:

    # /usr/sbin/usermod -L testuser
    

    You will see that the password field for testuser is preceeded by ! in /etc/shadow

    # /bin/grep testuser /etc/shadow
    testuser:!!$1$wypNKIu9$Ib3YmLexp7BVl88crX5eE/:14445:0:99999:2:::
    

    To disable the account completely use.

    $ chage -E0 testuser
    

Log in to reply
 

© Lightnetics 2024