user, group, passwd - alex-aleyan/linux_wiki GitHub Wiki

Brief:

  1. Useful Administrative Files:

    /etc/group            - Group account information.
    /etc/passwd           - user account information
    /etc/shadow           - secure user account information
    /etc/gshadow          - shadow secure user account information
    
    /etc/login.defs       - Shadow password suite configuration.
    /etc/default/useradd  - Default values for account creation.
    /etc/skel/            - Directory containing default files.
    /etc/pam.d/passwd     - PAM configuration for passwd.
    
  2. Useful Administrative Commands:

    useradd, adduser      - create a user
    groupadd              - create a user
    lslogins              - Lists user's info including the DEFAULT SHELL.
    chsh                  - Allows the user to change the user's login shell.
    usermod,passwd        - used to change user's account settings (authentication expiration, lock/unlock account).
    chfn                  - used to change a user's finger information (full name, office, office-phone, home-phone)
    

Remove user:

userdel -r username 

Set up User Name and Password on RHEL:

  1. Create a user:

    [root@test1 ~]# useradd user1
    [root@test1 ~]# echo $USER
    [root@test1 ~]# echo $USERNAME 
    
  2. Verify the user was created:

    [root@test1 ~]# cat /etc/passwd | grep user1
    user1:x:500:100::/home/user1:/bin/bash
    
  3. Create a group:

    [root@test1 ~]# groupadd users
    
  4. Verify that the group was created:

    [root@test1 ~]# cat /etc/group | grep users
    users:x:100:
    
  5. Add the user to the group:

    [root@test1 ~]# gpasswd -a <username> <groupname>
    [root@test1 ~]# gpasswd -a user1 users
    
  6. To set/cahnge password:

    [root@test1 ~]$ passwd
    [root@test1 ~]# passwd userName
    
  7. To delete a user from a group:

    [root@test1 ~]# gpasswd -d <username> <groupname>
    
  8. Hint: you can also use this command to list basic info of a user. Use ''lslogins'' by itself to list the summary about all accounts on a system.:

    lslogins userName
    OR
    lslogins id
    
  9. Edit Primary group of a user:

    usermod userName -g groupName
    

Your account has expired; please contact your system administrator:

Quick Review:

chage -l <username>
passwd -x -1 <username>
chage -m 0 <username>

On host1:

  1. Skip to Step 5; Remove user:
    userdel myuser
    
  2. Remove user’s home directory:
    rm –fr /home/myuser
    
  3. Add user:
    useradd user1
    
  4. Add the user to a group
    gpasswd -a myuser -g users
    
  5. List users to determine the UUID of the user:
    lslogins #to see UUID of myuser
    

On host2:

  1. SSH as root.

  2. Using the UUID from host1, change the UUID of myuser on host2 to match the UUID found on host1:

    usermod -u <matchin UUID> myuser

On all hosts do:

  1. Make sure the next parameters are set as:

    chage -l myuser
    Last password change					: Dec 22, 2016
    Password expires					: never
    Password inactive					: never
    Account expires						: never
    Minimum number of days between password change		: -1
    Maximum number of days between password change		: -1
    Number of days of warning before password expires	: -1
    
  2. if not, set them using:

    chage -E -1 –I -1 –m -1 –M -1 –W -1 myuser

Add a sudoer in RedHat:

  1. Uncomment the "%wheel ALL=(ALL) ALL" line:

    [root@test1 ~]# visudo
    ## Allows people in group wheel to run all commands
    # %wheel        ALL=(ALL)       ALL
    
  2. Optionally, add command path so the sudoers can launch the commands in the path:

    Defaults secure_path = /sbin:/bin:/<yourpathhere>

  3. List the users:

    [root@test1 ~]# cat /etc/passwd

  4. Add a user to sudoers group (wheel group is a group with god previleges):

    [root@test1 ~]# usermod -aG wheel <USERNAME>

  5. Test the sudoer:

    [root@test1 ~]# su <USERNAME>
    [user@test1 ~]$ groups #make sure user is in the wheel group
    [user@test1 ~]$ sudo whoami
    
  6. To remove a user from a group:

    gpasswd -d userName groupName

Reset Locked Account:

  1. Check if there are any failed logins. The below command will show how many failed logins the particular username has.

    #pam_tally --user <username>

  2. Unlock the user/Reset the failed logins

    #pam_tally --user <username> --reset

    • For all users, you can simply give

      #pam_tally --reset

⚠️ **GitHub.com Fallback** ⚠️