How to check users and user groups in Linux?
To view user and group information, you can use the following command:
- Check the current logged in user: whoami
This command will display the username of the current logged in user. - View all users: cat /etc/passwd
This command will display the usernames, user IDs, group IDs, home directories, and default shells of all users in the system. - Check which user groups the current user belongs to by using the command “groups”. This command will display all the user groups that the current user is a part of.
- View the user groups for a specified user by using the command “groups [username]”. This command will display all the user groups that the specified user belongs to.
- View user group information: cat /etc/group
This command will display the names, group IDs, and user lists of all user groups in the system.
Please note that these commands require superuser (root) privileges to view information on other users.