Posted: . At: 7:34 PM. This was 8 years ago. Post ID: 9453
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

How to list only the usernames in the /etc/passwd file on Linux.

This is how to list only the usernames in the /etc/passwd file. A very useful tip indeed. The -f1 parameter is the section that is shown.

jason@localhost ~ $ cut -d: -f1 /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
portage
nobody
sshd
man
messagebus
jason
polkitd

This is how to list all the home directories for each user account.

jason@localhost ~ $ cut -d: -f6 /etc/passwd
/root
/bin
/sbin
/var/adm
/var/spool/lpd
/sbin
/sbin
/sbin
/var/spool/news
/var/spool/uucp
/root
/var/tmp/portage
/var/empty
/var/empty
/usr/share/man
/dev/null
/home/jason
/var/lib/polkit-1

And finally, to list all login shells for each user account in the /etc/passwd file.

jason@localhost ~ $ cut -d: -f7 /etc/passwd
/bin/bash
/bin/false
/bin/false
/bin/false
/bin/false
/bin/sync
/sbin/shutdown
/sbin/halt
/bin/false
/bin/false
/sbin/nologin
/bin/false
/bin/false
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/bash
/sbin/nologin

Another way to list all users on a system and their information.

jason@localhost ~ $ getent passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/bin/false
daemon:x:2:2:daemon:/sbin:/bin/false
adm:x:3:4:adm:/var/adm:/bin/false
lp:x:4:7:lp:/var/spool/lpd:/bin/false
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
news:x:9:13:news:/var/spool/news:/bin/false
uucp:x:10:14:uucp:/var/spool/uucp:/bin/false
operator:x:11:0:operator:/root:/sbin/nologin
portage:x:250:250:portage:/var/tmp/portage:/bin/false
nobody:x:65534:65534:nobody:/var/empty:/bin/false
sshd:x:22:22:added by portage for openssh:/var/empty:/sbin/nologin
man:x:13:15:added by portage for man-db:/usr/share/man:/sbin/nologin
messagebus:x:101:249:added by portage for dbus:/dev/null:/sbin/nologin
jason:x:1001:1001::/home/jason:/bin/bash
polkitd:x:102:248:added by portage for polkit:/var/lib/polkit-1:/sbin/nologin

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.