Post Date: May 8, 2026
Last Updated: November 03, 2026
Introduction
Lock user account in Ubuntu 24.04 is an important task for Linux administrators who need to manage user access and improve server security. Temporarily disabling a user account helps prevent unauthorized password-based logins during security updates, employee account changes, or server maintenance.
Ubuntu 24.04 provides simple command-line utilities such as passwd and usermod to manage Linux user accounts. These commands allow administrators to lock or unlock user passwords without deleting accounts or removing personal files.
In this guide, we will explain how to lock and unlock a user account in Ubuntu 24.04 using Linux commands. You will also learn how to check user account status, verify password authentication, and troubleshoot common user management issues.
Prerequisites
Before proceeding, ensure you have the following requirements:
- A server or system running Ubuntu 24.04.
- Root or sudo privileges.
- Access to the terminal or SSH.
- Basic knowledge of Linux command-line operations.
- An existing Linux user account to manage.
Implementation
1. Lock a User Account in Ubuntu 24.04
To temporarily prevent a user from logging in using their existing password, use the passwd command with the -l option.
Command:
sudo passwd -l username
Example:
sudo passwd -l testuser
Output:
passwd: password expiry information changed
This command locks the user’s password by adding a lock marker to the encrypted password.
After executing this command, the user cannot authenticate using their existing password.
Note: Password locking does not necessarily block every authentication method. SSH public key authentication and other login mechanisms may still allow access.

2. Unlock a User Account in Ubuntu 24.04
If you want to restore password-based access to a previously locked account, use the passwd command with the -u option.
Command:
sudo passwd -u username
Example:
sudo passwd -u testuser
Output:
passwd: password expiry information changed
This command removes the password lock and allows the user to authenticate using their existing password, provided no other account restrictions apply.
3. Verify User Account Lock Status
After locking or unlocking a user account, you can verify its current password status using the passwd command with the -S option.
Command:
sudo passwd -S username
Example:
sudo passwd -S testuser
Sample Output:
testuser L 05/08/2026 0 99999 7 -1
The output displays information about the user’s password status.
Password status indicators:
L– The user’s password is locked.P– The user has a usable password.NP– The user does not have a password.
This command helps administrators confirm whether the password is currently locked or active.
4. Alternative Method: Lock a User Account Using usermod
Ubuntu also provides the usermod command to manage user account password settings.
To lock a user account using usermod, execute the following command.
Command:
sudo usermod -L username
Example:
sudo usermod -L testuser
This command locks the user’s password and prevents authentication using the existing password.
5. Unlock a User Account Using usermod
To unlock a previously locked user account, use the usermod command with the -U option.
Command:
sudo usermod -U username
Example:
sudo usermod -U testuser
This command removes the password lock from the user account.
Important: The usermod -U command may fail if the account does not have a usable password hash. In that situation, set a password using passwd or use the appropriate account-management procedure.
6. Check User Account Information
You can also verify whether a user account exists and inspect its account information using the id command.
Command:
id username
Example:
id testuser
Sample Output:
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
This command displays the user’s UID, primary group ID, and group memberships.
It helps confirm that the account exists on the Ubuntu system.
7. Troubleshooting Common Issues
While managing user accounts, administrators may encounter a few common issues.
Issue 1: Authentication token manipulation error
If you receive the following error:
passwd: Authentication token manipulation error
Check the following:
- Ensure you have root or sudo privileges.
- Verify that the filesystem is not mounted as read-only.
- Check the
/etc/shadowfile permissions. - Verify that sufficient disk space is available.
Issue 2: User account is still accessible after locking
Locking a password does not automatically terminate existing sessions or disable SSH key-based authentication.
To review active sessions, use:
who
To inspect the user’s SSH authorized keys, check:
sudo ls -la /home/username/.ssh/
If complete access restriction is required, review SSH authentication settings, running sessions, scheduled jobs, and other authentication mechanisms.
Issue 3: Unable to unlock the account
If the account cannot be unlocked, verify its password status:
sudo passwd -S username
If necessary, assign a valid password:
sudo passwd username
Then verify the account status again.
Conclusion
Ubuntu 24.04 provides simple command-line utilities for managing Linux user account access. Using passwd and usermod, administrators can temporarily lock or unlock password authentication without deleting user accounts or affecting their personal files.
By following this guide, you can lock and unlock a user account in Ubuntu 24.04, verify password status, and troubleshoot common account-management issues.
For improved server security, administrators should also review SSH key authentication, active user sessions, and other login methods when restricting user access.
Frequently Asked Questions (FAQs)
1. How do I lock a user account in Ubuntu 24.04?
You can lock a user account using the passwd -l command:
sudo passwd -l username
This prevents the user from authenticating with their existing password without deleting the account or its files.
2. How do I unlock a locked user account in Ubuntu 24.04?
Use the following command to unlock a user account:
sudo passwd -u username
This restores password-based authentication using the user’s existing password, provided no other restrictions apply.
3. How can I check whether a user account is locked or unlocked in Ubuntu?
Use the passwd -S command to check the user’s password status:
sudo passwd -S username
Related Articles
Install OpenLiteSpeed On Ubuntu
Create apache Virtual Hosts In Ubuntu
Talk to Our Linux Experts
Looking for reliable Linux server administration, Ubuntu management, DevOps, or infrastructure security solutions for your business?
Pheonix Solutions provides professional Linux and DevOps services to help businesses manage servers, strengthen system security, optimize infrastructure performance, and maintain reliable IT environments.
Explore our DevOps and Cloud Services to learn more about our Linux administration and infrastructure management solutions.
Need help managing Ubuntu servers or securing Linux user accounts? Contact our experts to discuss your infrastructure requirements and find the right solution for your business.
