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 -L|-U user   (Lock/Unock 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)
    • passwd -l|-u user  (Lock / Unlock user account)
  • id user                      (List the user and its groups)
  • 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
    • who -a
  • Config Files:
    • /etc/passwd
    • /etc/shadow
    • /etc/login.defs
    • /etc/default/useradd
    • /etc/skel/   (Contain files that will be copied to newly created user’s home directory e.g .bash_profile, .bashrc)

Group commands:

  • groupadd grp         (Create a new group)
  • groupdel grp          (Delete a group)
  • groupmod -o oldgrp -n newgrp  (Modifies group name) 
  • groups user1 user2; id -Gn user          (List groups of a user)
  • gpasswd grp
  • Config Files
    • /etc/group
    • /etc/gshadow
Advertisements

About Ishtiaque

I am IBM Certified Infrastructure Systems Architect, TOGAF 9 Certified, ITIL V3 Foundation certified and Oracle Certified Export in Java Web Component Developer with over 10 years of support and development experience in IBM middleware software and Java. Additionally, have a sound grip in databases, Linux and OpenStack administration. I hold the following certifications: IBM Certified Infrastructure Systems Architect 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 LFCS, Linux and tagged . Bookmark the permalink.