Reading Time: 3 minutesAdding a user in CentOS
is a common task for most Linux admins. Users have unique username’s and occasionally you may wonder if a username is in use or need other details about the user (like their group ID). We’ll show you how to see a list of users after logging into your Liquid Web CentOS 7 server
. Once you’ve logged in via SSH, you’ll be able to run the commands below and get the information you need. Let’s get started!
To get a simple list of user names, enter the command below
and press Enter
root@host [~]# cut -d: -f1 /etc/passwd
This command gives us a list of users assigned to this CentOS server including system users like:
command is also a common method to look up user details as it pulls info from the passwd, group and other databases that stores the users information. The databases it searches in are:
- ethers (Ethernet addresses)
To search for a specific service noted in the services database
, the following command lists the service currently running on port 22:
root@host [~]# getent services 22
The getent hosts
command lists the recognized hosts:
root@host [~]# getent hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.67.227 host.domain.com host host2.domain.com host2
If you’d like a more detailed list of users, you can use the command below. Using this command will provide you with the username, UID, GID, User Details, their home directory path, and the Default Shell type for the user.
root@host [~]# getent passwd root
In this example above, you’ll see each field is separated by colons. Let’s breakdown the sections to provide more information on the user.
- Username – the user example is root. Other users include bin, daemon, systemd-network, among many others. These are for when these entities need to access the system.
- Password – indicated by the letter x, you can also find this encrypted password in the /etc/shadow file.
- UID – this is the user’s ID, indicated by number starting at 1000. The root user is special as its UID is 0.
- GID – like the user ID, the group ID shows us the group that a user belongs to. The GID also starts at 1000 and for the root users, the group number is 0.
- User Details – usually you’ll find the user’s first name. Sometimes this field can also be left blank.
- Home Directory – this is the path that a user is in when logging into the server. You can alter this path by chrooting a user’s path.
- Default Shell – A shell allows for an environment where users interact with the server and the type of shell assigned allows for different usage. The /bin/bash shell allows for text files to run commands.
For a quick overview of usage options, use the – -usage flag:
root@host [~]# getent --usage
Usage: getent [-i?V] [-s CONFIG] [--no-idn] [--service=CONFIG] [--help]
[--usage] [--version] database [key ...]
- -s service, –service service: This flag overrides all the databases with the specified service.
- –s database:service, –service The database:service flag overrides only the specified databases with the specified service. The option may be used multiple times, but only the last service for each of the databases will be utilized.
- -i, –no-idn: This flag disables the IDN encoding in the lookups for ahosts and getaddrinfo (3)
- -?, –help: This flag prints a usage summary and then exits.
- –usage: This flag prints a short summary of usage examples.
- -V, –version: This flag prints the version number, license, and the warranty disclaimer for getent.
Any one of the following exit values can be utilized to return info by getent:
- 0: This exit status shows that the command completed successfully.
- 1: This exit status shows that there’s a missing argument, or database unknown.
- 2: This exit status shows that One or more supplied key could not be found in the database.
- 3: This exit status shows that the Enumeration not supported on this database.