Locking and unlocking accounts on Linux programs

There are occasions when locking a Linux person account is critical and instances when you’ll want to reverse that motion. Listed below are instructions for managing account entry and what’s behind them.

A mysterious and complex padlock with advanced circuits” class=”lazy” data-original=”https://pictures.idgesg.internet/pictures/article/2019/10/cso_cybersecurity_mysterious_padlock_complex_circuits_gold_by_sqback_gettyimages-1177918748_2400x1600-100813830-large.jpg” itemprop=”contentUrl” loading=”lazy” onload=”attempt catch(e) “>

SQBack / Getty Pictures

If you’re administering a Linux system, there’ll possible be instances that you’ll want to lock an account. Possibly somebody is altering positions and their continued want for the account is underneath query; perhaps there‚Äôs cause to consider that entry to the account has been compromised. In any occasion, figuring out the right way to lock an account and the right way to unlock it ought to it’s wanted once more is one thing you want to have the ability to do.

One necessary factor to bear in mind is that there are a number of methods to lock an account, they usually do not all have the identical impact. If the account person is accessing an account utilizing public/non-public keys as an alternative of a password, some instructions you would possibly use to dam entry to an account won’t be efficient.

Locking an account utilizing the passwd command

One of many easiest methods to lock an account is with the passwd -l command. For instance:

$ sudo passwd -l tadpole

The impact of this command is to insert an exclamation level as the primary character within the encrypted password discipline within the /and so forth/shadow file. This is sufficient to preserve the password from working. What beforehand seemed like this (observe the primary character):


will appear like this:


On his subsequent login try (ought to there be one), tadpole would most likely attempt his password quite a few instances and never acquire entry. You, then again, would be capable of test the standing of his account with a command like this (-S = standing):

$ sudo passwd -S tadpole
tadpole L 10/15/2019 0 99999 7 -1

The “L” within the second discipline tells you that the account is locked. Earlier than the account was locked, it could have been a “P”. An “NP” would imply that no password was set.

The usermod -L command would have the identical impact (inserting the exclamation character to disable use of the password).

One of many advantages of locking an account on this approach is that it’s extremely simple to unlock the account when and if wanted. Simply reverse the change by eradicating the added exclamation level with a textual content editor or, higher but, by utilizing the passwd -u command.

$ sudo passwd -u tadpole
passwd: password expiry info modified.

The issue with this strategy is that, if the person is accessing his or her account with public/non-public keys, this variation won’t block their use.

Locking accounts with the chage command

One other method to lock a person account is to the the chage command that helps handle account expiration dates.

$ sudu chage -E0 tadpole
$ sudo passwd -S tadpole
tadpole P 10/15/2019 0 99999 7 -1

The chage command goes to make a refined change to the /and so forth/shadow file. The eighth discipline in that colon-separated file (proven under) will probably be set to zero (beforehand empty) and this implies the account is actually expired. The chage command tracks the variety of days between password modifications, but in addition offers account expiration info when this selection is used. A zero within the eiighth discipline would imply that the account expires a day after January 1, 1970, but in addition merely locks it when a command like that proven above is used.

$ sudo grep tadpole /and so forth/shadow | fold
+— days till expiration

To reverse this variation, you possibly can merely take away the Zero that was positioned within the /and so forth/shadow entry for the person with a command like this:

% sudo chage -E-1 tadpole

As soon as an account is expired on this approach, even passwordless SSH won’t present entry.

Be part of the Community World communities on




to touch upon matters which can be high of thoughts.


Germany Devoted Server

Leave a Reply