To lock an account on Linux, you can use the passwd
command with the -l
option. This option allows you to lock the password for the specified account, preventing the user from logging in to the system.
For example, to lock the account for the user john
, you can use the following command:
$ sudo passwd -l john
This will lock the password for the user john
, and the user will not be able to log in to the system until the password is unlocked.
You can also use the usermod
command with the --lock
option to lock an account. This command allows you to modify the properties of a user account.
For example, to lock the account for the user john
, you can use the following command:
$ sudo usermod --lock john
This will lock the account for the user john
, and the user will not be able to log in to the system until the account is unlocked.
To unlock an account that has been locked, you can use the passwd
or usermod
command with the -u
or --unlock
option.
For example, to unlock the account for the user john
, you can use the following command:
$ sudo passwd -u john
Or:
$ sudo usermod --unlock john
This will unlock the account for the user john
, and the user will be able to log in to the system again.
Note that locking or unlocking an account does not affect the user's ability to access other resources, such as files and directories. To restrict access to these resources, you can use file permissions and access controls.