User and Group Management

user-and-group-management

Create new user

Linux daddy will guide you.

sudo adduser username

You are now a daddy

sudo useradd username

useradd

Check all the users

sudo cat /etc/shadow

etc shadow

Consider,
abhishek2:!:19579:0:99999:7:::

The row is split into 9 fields seperate by :

Each field resembles as:

  1. Username. User account and login name that exist in the system.

    1. Encrypted password. Password using the format $type$salt$hashed and eight to 12 characters long.
    2. Last password change. Date since Jan. 1, 1970, when the password was last changed.
    3. Minimum password age. The minimum number of days that must elapse before the password can be changed by the user.
    4. Maximum password age. The number of days after which the password must be changed.
    5. Warning period. The number of days before the password expires, during which time the user gets a warning to change the password.
    6. Inactivity period. The number of days post-expiration — since Jan. 1, 1970 — before the user’s account is disabled.
    7. Expiration date. The date on which the account was disabled.
    8. Unused. This field is left empty and reserved for future use

User with custom shell

sudo useradd -s /bin/bash abhishek
  • /bin/bash -> env shell

User with own home directory

sudo useradd -m -d /home/abhishek abhishek
  • /home/abhishek4 -> this can be any path

User with comment

sudo useradd -c "user name is abhishek" abhishek

User with the account expiery date

useradd -e 2023-08-32 apple
  • -e -> The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD.

User with custom userId

sudo useradd -u 1822 abhishek

Change default home directory of user geet

usermod -d /var/tmp/user/geet -m geet

Change login name of user geet

sudo usermod -i geet GEET 

Change default shell of user geet

usermod -s /bin/fish geet

Set user password

sudo passwd username

add user passswd

Switch user

su username

add new group with own home directory with custom user id and group and custom comment to user geet, with login shell bash

useradd -m -d /home/geet -u 1029 -g 1822 -c "geet user" -s /bin/bash geet

Create new group

Create a new group

Linux daddy will guide you

sudo addgroup groupName

addgroup

You are now daddy

sudo groupadd grp1

create new group

Create group with custom ID

sudo groupadd -g 2218 groupName

Add user to group

# sudo usermod --append --groups demo user1
sudo usermod -aG groupname userName

usermod

Display details about group

sudo cat /etc/gshadow

Change primary group of geet to ak

sudo usermod -g ak geet

Add geet as a menber of group jeet

sudo gpasswd -M geet jeet

Remove user geet from group jeet

sudo gpasswd -d geet jeet

Make geet admin of group jeet

sudo gpasswod -A geet jeet

Set password for group jeet

sudo gpasswd jeet

Delete user and group

Delete user

sudo userdel geet

Delelet user with all files

sudo userdel -r geet

Delete Group

sudo groupdel jeet

If the article helps you, leave a like, follow, or anything 🙂.

You can follow me on LinkedIn and GitHub.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
best-practices-for-end-to-end-testing-implementation-in-cloud-migration

Best Practices for End-to-End Testing Implementation in Cloud Migration

Next Post
expanding-our-fully-homomorphic-encryption-offering

Expanding our Fully Homomorphic Encryption offering

Related Posts