Show all user account in a Linux system
cat /etc/passwd
tail /etc/passwd
Example:
telson:x:1000:1000:telson:/home/telson:/bin/bash
telson:x:1000:1000:telson:/home/telson:/bin/bash
userName:password:UID:GID:user-info:homeDir:defaultShell
The user login password is stored in /etc/shadow file.
tail /etc/shadow
- “*” – user cannot login
- “!” – user login locked
Show user group accounts
tail /etc/group
The current shell can be “replaced” with the exec command. The updates take effect without logoff or restart
$ exec su -l $USER
Create user treesa with home directory and bash shell
useradd -m -d /home/treesa -s /bin/bash treesa
Create a user teena with home directory, shell and comment
sudo useradd teena -m -s /bin/bash -c “Admin User”
Add user teena to the sudo group
sudo usermod -aG sudo teena
Change user password
sudo passwd treesa
Update “/etc/passwd” password file to change the home directory
Skeleton directory
Skeleton directories serves as the foundation for a new user’s home directory when created using the useradd command. It automatically copies files and directories in /etc/skel to the user’s home directory.
$ ls -al /etc/skel
Lock the user account
usermod -L treesa
Unlock the user account
usermod -U treesa
Delete the user
userdel treesa
How to add a user to Sudoers in Ubuntu
usermod -aG sudo user1
Add a new group student
sudo groupadd -g 2222 student
Add a new user and group – user1 with bash shell, home directory
sudo useradd -m -g user1 -s /bin/bash user1
Change userID to 2222 for teena
sudo usermod -u 2222 teena
Change password for user teena
sudo passwd teena
Change the shell for user teena
sudo chsh -s /bin/bash teena
chsh: PAM: Authentication failure
Replace the following line of code in /etc/pam.d/chsh:
auth required pam_shells.so
with
auth sufficient pam_shells.so
Disable shell login for user treesa
sudo chsh -s /sbin/nologin treesa