This brief tutorial shows students and new users how to list user accounts in Ubuntu Linux.
Learning to list users on Ubuntu Linux can be useful for system administrators or anyone managing a Linux server. It allows them to view all the User accounts on the system and manage them as needed.
By listing all the user accounts, administrators can identify any unauthorized accounts, ensure that all accounts are properly configured, and manage permissions and access for each account.
Additionally, knowing how to list users can help troubleshoot and diagnose issues related to users and permissions.
Learning how to list users on Ubuntu can be a valuable skill for students and new users as they begin to explore and work with Linux systems.
List User in the passwd file
One popular option for listing User accounts on Ubuntu is to view the content of the /etc/passwd file.
This file stores local user account information from the login name to the encrypted password and account ID. So, to view all User accounts on the system, run the commands below:
less /etc/passwd
When running the commands above, it should list the content of the /etc/passwd file. In there, you’ll see all the accounts created on the server.
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin .
You can also use the cat /etc/passwd command to output the same list.
This can be unclear for students and new users if they don’t know how to read the file’s content. However, each line in the file is a single account identity. There are seven fields delimited by colons that contain the following:
- User name
- Encrypted password (x means that the password is stored in the /etc/shadow file)
- User ID number (UID)
- User’s group ID number (GID)
- Full name of the User (GECOS)
- User home directory
- Login shell (defaults to /bin/bash)
Now, if you just want to list the account names and not all the other details, simply run the commands below:
awk -F: '{ print $1}' /etc/passwd
That should list only the account names on the system, beginning with the root account.
root daemon bin sys sync games man .
That’s option number 1
Get User List via Getent Tool
Another option to get all User accounts on the system is to use the getting tool. This tool does a similar function as the commands above.
It lists the content of the /etc/passwd file using the database info stored in the /etc/nsswitch.conf file.
To get the lists of users using the getent, run the commands below:
getent passwd
It should list the same content as above:
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin .
The /etc/nsswitch.conf is used to configure which services are to be used to determine information such as hostnames, password files, and group files.
These two options should be enough to get you a list of users on Linux systems, including Ubuntu.
Leave a Reply Cancel reply