Aiden
Aiden

Reputation: 399

Filtering /etc/passwd to only show regular users

when trying to display the following file

etc/passwd

Is there a way to just show regular users that would login and have a home directory instead of all these pseudo-users that seem to be part of system processes.

root:x:0:0:root:/root:/bin/bash 
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mike:x:1000:1000:mike,,,:/home/mike:/bin/bash <-- THIS ONE HAS A HOME DIRECTORY 

Thanks

Aiden

Upvotes: 0

Views: 2986

Answers (2)

Keith Thompson
Keith Thompson

Reputation: 263197

I don't think there's any reliable way to do this.

Accounts for ordinary users commonly have uids greater than or equal to 1000, but that's only a convention. I've seen plenty of systems that don't follow that convention, and plenty of accounts that violate it, even on systems that try to follow it. And the nobody system account commonly has a uid like 65534.

Similarly, user accounts typically have gone directories under /home, but there are violations of that convention in both directions.

UNIX and UNIX-like systems make no firm distinction between user and system accounts (other than root).

The best you can do is to carefully examine the /etc/passwd file on the system you're interested in, and/or talk to the person in charge of creating accounts on that system, and try to derive some ad hoc rules -- and don't be surprised if a new account created tomorrow violates those rules. Someone a non-user account is created that deliberately acts like a user account, for testing purposes.

You might consider reformulating your requirements. Exactly what problem are you trying to solve?

One more thing: account information isn't always stored in /etc/passwd. Some systems use other mechanisms like NIS or LDAP. The getent passwd command (if your system has it) should allow for that.

Upvotes: 0

larsks
larsks

Reputation: 311328

Well, you could ask for all accounts that have home directories in /home:

awk -F: '$6 ~ /\/home/ {print}' /etc/passwd

Some systems keep system accounts below a specific user id, so you can ask for all accounts with UIDs higher than some limit:

awk -F: '$3 >= 1000 {print}' /etc/passwd

Upvotes: 1

Related Questions