User and group commands in Linux

User commands:

  • useradd  (-d: directory; -s: shell; -G: group list; -c: comments)  
    • useradd -m user    (-m: create user home directory)
    • useradd myuser -d /home/myuser -s /bin/csh -G grp1,grp2 -c “My User”
  • userdel -r user             (Remove user and its home directory) 
  • usermod  (-aG: append groups, -L: lock; -U: unlock, -e: expire)
    • usermod -aG grp1,grp2 user  (Add user into groups)
    • usermod -G “” user      (Removes user from all secondary groups) 
    • usermod -L -e 1 user   (Lock and expire a user account)
    • usermod -U user          (Unlock a user account)
  • chage  (-l: List; -E: yyyy-mm-dd; -m: min; -M: max; -d: days)
    • chage -l user    
    • chage  -E  2017-12-30  -m 10 -M 20 user
    • chage -d 0 user       (Force password change on next user login)
  • passwd:  (-l: lock; -u: unlock, -S: status, -e: expire)
    • passwd user             (Reset password for the user)
    • echo password | passwd –stdin user     (Change password from echo)
    • passwd -l|-u user    (Lock / Unlock user account)
  • id [-Gnuser                       (List the user and its groups)
  • groups user                        (List groups of user)
  • pdbedit -Lv                        (List samba users)
  • pam_tally2
    • pam_tally2                     (List locked users)
    • pam_tally2 -r -u user    (Reset locked user)
  • List all users & home directories:
    • cut   -d:   -f 1,6   /etc/passwd
    • awk -F:   ‘{print $1,$6}’   /etc/passwd
  • Setup Restricted/Limited account:
    • ln -s /bin/bash  /bin/rbash; usermod -s /bin/rbash user
  • Show logged in users:
    • users           (Show name of the users currently logged in)
    • who -a        (Show all login users)
    • whoami      (prints effective userid)
  • Show last logged in users:
    • last [user]      (Show detailed listing of all or specific last logged in users) 
    • lastlog            (show only last logged in users name)
    • last | grep user | tr -s ‘ ‘ | cut -d’ ‘ -f1,3 | sort -k2 | uniq
  • Config Files:
    • /etc/passwd
    • /etc/shadow
    • /etc/login.defs              (Changes user default login settings)
    • /etc/default/useradd   (Contains user account default settings)
    • /etc/skel/                        (Contain files that will be copied to home dir)

Group commands:

  • groupadd grp                                    (Create a new group)
  • groupdel grp                                     (Delete a group)
  • gpasswd -a|-d  user1 grp1              (Adds|Deletes user1 into grp1)
  • lid -g grp1                                           (List members of grp1)
  • groups user1 user2; id -Gn user    (List groups of a user)
  • groupmod -o oldgrp -n newgrp  (Modifies group name) 
  • Config Files
    • /etc/group
    • /etc/gshadow

About Ishtiaque

I am IBM Certified Infrastructure Systems Architect, Linux Foundation Certified System Administrator, Oracle Certified Programmer in Java and Web Component Developer, and TOGAF 9 certified with over 10 years of support and development experience in IBM middleware software and Java. Additionally, have a sound grip in databases and OpenStack administration. I hold the following certifications: IBM Certified Infrastructure Systems Architect Linux Foundation Certified System Administrator (LFCS) TOGAF 9 Certified Oracle Certified Expert, Java EE6 Web Component Developer Oracle Certified Professional – Java 6 Programmer ITIL v3 Foundation Certified IBM Certified Solution Architect – Cloud Computing Infrastructure V1 IBM Certified System Administrator – WebSphere Portal V8, V7, V6.1, V6 IBM Certified System Administrator – WebSphere Application Server V7, V6.1 IBM Certified System Administrator – AIX V7 IBM Certified System Administrator – WebSphere MQ V7 IBM Certified Deployment Professional – Business Process Manager Advanced V7.5 IBM Certified Solution Advisor – Cloud Computing Architecture V3 IBM Certified Solution Developer – WebSphere Portal V5.1
This entry was posted in LFCE, LFCS, Linux and tagged . Bookmark the permalink.