# πŸ§‘β€πŸ’» Linux User & Group Management Cheat Sheet --- ## πŸ” Viewing User Info from `/etc/shadow` ```bash cat /etc/shadow ``` Example entry: ```bash radin:$y$j9T$gxn.Bgl/nVnzPEeWn0Hrz.$CEeQGtg1TlZ/jwu9Zsz2kkIq3dBtbhJ/bzhVT7cJ1.9:20270:0:99999:7::: ``` | Field | Description | Example | | ----------------- | -------------------------------------------- | ----------------------------------------------- | | πŸ‘€ Username | User’s login name | `radin` | | πŸ”’ Password Hash | Encrypted password | `$y$j9T$gxn.Bgl/nVnzPEeWn0Hrz.$CEeQGtg1TlZ/...` | | πŸ—“οΈ Last Changed | Days since Jan 1, 1970 when password changed | `20270` (which is 20270 + 1970 = year) | | ⏳ Min Age | Minimum days between password changes | `0` | | ⏰ Max Age | Maximum days before password must be changed | `99999` | | ⚠️ Warning Period | Days before expiration user is warned | `7` | --- ## πŸ›‘οΈ Viewing Groups from `/etc/group` ```bash cat /etc/group ``` Example: ```bash radin:x:1000: sudo:x:27:radin ``` | Field | Description | Example | | ------------- | ------------------------------------ | --------------- | | πŸ‘₯ Group Name | Name of the group | `radin`, `sudo` | | πŸ”‘ Password | Password (usually `x` means none) | `x` | | πŸ†” GID | Group ID | `1000`, `27` | | πŸ‘€ Users | Users in the group (comma-separated) | `radin` | --- ## πŸ‘₯ Check Groups for a User ```bash groups ``` --- ## πŸ†” View User and Group IDs ```bash id ``` Example output: ```bash uid=1000(radin) gid=1000(radin) groups=1000(radin),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users),114(lpadmin) ``` --- ## βž• Adding Users | Command | Description | | -------------------------------------- | ----------------------------------------- | | `useradd ` | Add user without home directory | | `useradd -m ` | Add user **with** home directory | | `useradd -s /bin/bash -m ` | Add user with bash shell & home directory | | `useradd -G group1,root -m ` | Add user with home and extra groups | --- ## πŸ”‘ Changing Password ```bash passwd ``` --- ## ❌ Deleting Users | Command | Description | | ----------------------- | ------------------------------------ | | `userdel ` | Delete user | | `userdel -r ` | Delete user and their home directory | | `userdel -f ` | Force delete user | --- ## πŸ”§ Modifying Users (`usermod`) | Command | Description | | ---------------------------------------- | ----------------------------------------- | | `usermod [options] username` | Modify user with various options | | `usermod -l ` | Rename user | | `usermod -d -m ` | Change user home directory and move files | | `usermod -G ` | Set new groups (replaces old groups) | | `usermod -aG ` | Add user to a supplementary group | | `usermod -s ` | Change user login shell |