Key Takeaways
- You tin database personification accounts connected Linux utilizing commands for illustration "cat /etc/passwd" aliases "getent passwd".
- Extraneous and unused accounts conscionable adhd clutter to your system, and they whitethorn moreover coming a information risk, depending connected your situation.
Linux is simply a multiuser operating system, truthful creating galore personification accounts is easy. Over time, it's easy to suffer way of which accounts are required. Listing personification accounts helps you negociate them.
Usually, other accounts conscionable adhd clutter, but they tin besides unfastened up information vulneraiblities.
Advances successful exertion often bring their ain caller problems. As soon arsenic computers were capable to support aggregate users, nan request to ring-fence and encapsulate each person's activity from everyone other became apparent. This led to nan conception of user accounts. Each personification has a named ID and a password. These are nan credentials that fto them log into their account. Their files are kept successful an area that is backstage to each user.
On a engaged system, it is easy to suffer show of which accounts you person created, and which are nary longer needed. From a information constituent of view, it is bad believe to support personification accounts that you nary longer request to beryllium configured and accessible connected your computer. You should remove those users.
Even if you don't person different group utilizing your machine you mightiness person created immoderate accounts conscionable to study really to do it, aliases to study and believe management processes.
The first measurement is to database nan personification accounts that are configured connected your computer. That lets you reappraisal them and make a judgement telephone connected which tin beryllium deleted. There are respective methods to database users. No matter which distribution you're using, these techniques should activity for you without needing to instal immoderate applications aliases utilities.
List Users With nan feline Command
A database of nan configured users is maintained, on pinch accusation astir each user, successful nan "/etc/passwd" file. This is simply a matter record that regular users tin database to nan terminal window. You don't request to usage sudo to look into nan "/etc/passwd" file.
We tin usage nan feline bid to nonstop nan contents of nan "/etc/passwd" record to nan terminal window. This will database nan full contents of nan file. This intends you'll besides spot nan entries for personification accounts that are owned by processes and nan system, not by people.
cat /etc/passwdThere's a statement of dense accusation reported for each personification account.
The accusation for nan personification relationship called "dave" contains these pieces of information, pinch colons ":" betwixt them.
- dave: The sanction of nan personification account. Usually nan sanction of nan personification who owns nan account.
- x: At 1 time, this held the password for nan account. Nowadays, passwords are stored successful nan "/etc/shadow" file. The "x" intends nan password is successful that file.
- 1000: The personification ID for this account. All personification accounts person a unsocial numeric ID. Regular personification accounts usually commencement astatine 1000, pinch each caller relationship taking nan adjacent free ID, specified arsenic 1001, 1002, and truthful on.
- 1000: The group ID of nan default group nan personification belongs to. In normal circumstances, nan default group has nan aforesaid worth arsenic nan personification ID.
- dave,,,: A postulation of optional other accusation astir nan user. This section contains information pinch commas "," betwixt them. They tin clasp things for illustration nan afloat sanction of nan user, their agency number, and their telephone number. The introduction for personification relationship "mary" shows her afloat sanction is Mary Quinn.
- /home/dave: The way to nan user's location folder.
- /bin/bash: The default ammunition for this user.
If we pipe nan output from this bid done nan wc inferior and usage nan -l (lines) action we tin count nan lines successful nan file. That'll springiness america nan number of accounts configured connected this computer.
cat /etc/passwd | wc -lThat fig includes nan strategy accounts and users created by applications. There are astir 400 regular users configured connected this computer. Your consequence is apt to beryllium a batch less.
With that galore accounts, it's much convenient to usage little to position nan "/etc/passwd" file.
less /etc/passwdUsing little besides allows you to hunt wrong nan output, should you want to look for a peculiar personification account.
The awk Command
Using the awk command we tin show conscionable nan username. This tin beryllium useful erstwhile you're penning a book that needs to do thing to a batch of personification accounts. Listing nan personification relationship names and redirecting them into a matter record tin beryllium a awesome clip saver. All you request to do past is transcript and paste nan remainder of nan bid onto each line.
We'll show awk to usage nan colon ":" arsenic nan section separator, and to people nan first field. We'll usage nan -F (field separator) option.
awk -F: '{print $1}' /etc/passwdThe personification relationship names are written to nan terminal model without immoderate of nan different relationship information.
The trim Command
We tin execute nan aforesaid benignant of point utilizing the trim command. We request to usage nan -d (delimiter) action and inquire it to prime nan first section only, utilizing nan -f (fields) option.
cutr -d: -f1This lists each of nan personification accounts, including nan strategy and different non-human accounts.
The compgen Command
The compgen bid tin beryllium utilized pinch nan -u (user) action to database nan personification accounts. We'll tube nan output done nan file bid to database nan personification accounts successful columns, alternatively of 1 agelong database pinch a azygous personification sanction per line.
compgen -u | columnAgain, nan first personification accounts listed beryllium to processes, not humans.
UID MIN and UID MAX
User accounts are fixed a numeric ID, which we saw earlier. Usually, nan regular quality personification accounts commencement astatine 1000, and nan system, non-human, personification accounts commencement astatine 0. The ID of the guidelines account is 0.
If we tin verify nan lowest and highest imaginable personification IDs, we tin usage that accusation to prime nan personification accounts that are betwixt those 2 values. That will fto america prime only nan personification accounts belonging to existent people.
Linux keeps way of these 2 values utilizing configuration parameters called UID_MIN and UID_MAX . These are held successful nan "/etc/login.defs" file. We tin easy spot these values utilizing grep.
We're going to usage nan -E (extended regex) option. Our hunt drawstring looks for lines that statesman pinch "UID_MIN" aliases "UID_MAX" successful nan "/etc/login.defs" file. The caret "^" represents nan opening of a line.
grep -E '^UID_MIN|^UID_MAX' /etc/login.defsThe scope for personification IDs connected this machine is from 1000 to 60,000.
The getent Command
The getent bid sounds accusation from strategy databases. We tin show it to database nan entries successful nan "/etc/passwd" record by utilizing "passwd" arsenic a parameter.
getent passwdThis gives america nan aforesaid readout we tin get utilizing cat. But wherever getent shines is by accepting values known arsenic "keys." A cardinal dictates which accusation getent reports on. If we want to spot nan introduction for a azygous user, we tin walk successful their personification relationship sanction connected nan bid line.
getent passwd SarahNote that nan personification relationship sanction is case-sensitive.
getent passwd sarahWe tin besides walk successful nan precocious and little limits of nan personification relationship IDs we want to see. To spot perfectly each nan regular personification accounts, we tin usage nan values from UID_MIN and UID_MAX.
getent passwd {1000..60000}This takes immoderate clip to run. Eventually, you'll beryllium returned to nan bid prompt.
The logic for nan agelong execution clip is that getent tries to find matches for each of nan personification relationship values correct up to 60000.
Let's spot what nan highest personification relationship ID is. We'll usage nan trim command, but this clip we'll inquire for section three, nan personification ID field. We'll tube nan output done benignant and usage nan -g (general numeric sort) option.
cut -d: -f3 /etc/passwd | benignant -gThe highest ID worth of a human-owned personification relationship is 1401.
User id 65534 is assigned to nan strategy conception of "nobody."
getent passwd {65534..65534}So we cognize that alternatively of utilizing nan UID_MAX worth of 60000, connected this machine we tin usage a much realistic worth for illustration 1500. That'll velocity things up nicely. We'll besides tube nan output done trim to extract conscionable nan names of nan personification accounts.
getent passwd {1000..1500} | trim -d: -f1
The users are listed and we're returned instantly to nan bid prompt.
Instead of piping nan output done cut, let's tube nan output done wc and count nan lines erstwhile more. That'll springiness america nan number of "real" personification accounts.
getent passwd {1000..1500} | wc -lWe tin now spot that connected this computer, definitively, location are 400 configured, human-owned, personification accounts.
Power and Simplicity
One of these techniques is judge to suit your needs erstwhile you request to reappraisal nan personification accounts connected a Linux computer. These commands should beryllium coming connected each distributions, and nary of them require sudo access, truthful they are each disposable to each user.