Managing users in Linux
The data about users is stored in /etc/passwd. Editing it manually is usually a bad idea. You can read about its structure
here.
/etc/group stores info about groups. Each user has a primary group, named the same as the user, and may be in supplementary groups (like sudo, fuse, etc.).
# Commands
who- show who is logged inwhoami- current user namesu- substitute user. Execute commands or log in as another user. Set torootby default.su username- switch to a given usersu - username- switch to a given user and simulate a full login shell
sudo <some_command>- execute command asroot. Unlikesu, will request the password of the current user, notrootpassword. The user is required to be insudogroup. See also sudo.id- get user group (or other) id, e.g.id -g psharen
Modify users:
adduser [_login_]- add a userdeluser [_login_]- delete userusermod- modify user accountusermod -aG group1,group2 user- add user to groups-a- append, used only with-G-G- groups
gpasswd -a username group- also add user to groupsadduser [_login_] [_group_]- also add user to groupspasswd [_user_]- set passwords. Defaults to current user, but can edit other users’ as well, if underroot.
Groups:
groups <username>- display the user’s groups, defaults to current useraddgroup- create groups (only root can do that). There’s alsogroupadd, but it’s more for scripting purposes. On my machine,addgroupis a symlink toadduserdelgroup- delete groups
# Useful
- How to List Users in Linux warning: scripts are mostly not functional
- How To Edit the Sudoers File | DigitalOcean
- Groups and processes, how it works under the hood
- SystemGroups - Debian Wiki - has some info about system groups like
cdrom,fuse, etc. Those are mostly obselete. - GID, current, primary, supplementary, effective and real group IDs?
- How do groups work on Linux?
- addgroup vs groupadd