Linux as an operating system holds the capabilities of handling multiple users. So it is important to keep a check on the users and their related information in order to maintain the integrity and security of the system. Whenever a user is added its information is stored in the “/etc/passwd” file. It keeps the username and other related details. Here are some commands to fetch username and its configurations from the Linux host. There is no specific “username” command in Linux but there are other several sets of commands that let the user access the various users on the machine.
1. id: This command basically prints the information of real and effective user or in other words the current user.
Use the id command followed by the username to print specific user information.
2. getent: This command fetches user information from database configured in /etc/nsswitch.conf. file which also includes passwd database.
Each line above has seven fields separated by colons which contains the following information-
- Encrypted Password
- User ID number(UID)
- User group ID number(GID)
- Full name of the user(GECOS)
- user home directory and
- Login shell respectively.
3. finger: It displays the current user’s real name along with the terminal name, write status, idle time, and login time.
Use the finger command followed by the username to print specific user information.
4. lslogins: It displays information about known users in the system. By default, it will list information about all the users in the system.
5. cat: This command fetches and prints user information from /etc/passwd/ file, where each line contains seven fields as in the output of getent and less command.
6. compgen: This command also displays the name of all the users without any additional information.
Note: One can use compgen -c command to list all commands available if he/she is not the admin on a Linux system and doesn’t have the sudo access.
- How to Change the username or userID in Kali Linux?
- Node | URL.username API
- 'IPCS' command in Linux with examples
- select command in Linux with examples
- Sed Command in Linux/Unix with examples
- ZIP command in Linux with examples
- SORT command in Linux/Unix with examples
- Cat command in Linux with examples
- Head command in Linux with examples
- Tail command in Linux with examples
- wc command in Linux with examples
- tar command in Linux with examples
- atrm command in Linux with examples
- bc command in Linux with examples
- AWK command in Unix/Linux with examples
- tr command in Unix/Linux with examples
- mv command in Linux with examples
- Paste command in Linux with examples
- comm command in Linux with examples
- cmp Command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet