How to Add Remove Rename a User and User Group in Linux

20:54
In this blog we are going to see the see

How to Add or Remove a User and User Group in Linux

Let's jump into the List of Commands. The user name is efxx Top 6 command-line based browsers read more...
In this blog we will learn how to create a new user new group and add them or remove them from the system or specified group. Basically this is the list of commands to do some useful things on Linux. Please usethem carefully and let me know the errors or any thing you need apart from this. Thank you. Add a user (the users password will be added in /etc/shadow with other user passwords)
Note: Basic difference "adduser, useradd". "adduser" will create home directory and add skeleton(directory where you can place the default files and all the folders) files to that directory where "useradd" wont create any home directory and files !
Check list of all Users and Access Linux
List of users in Linux
$ cut -d: -f1 /etc/passwd
or
$ awk -F: '{ print $1,"   \t" $NF,"   \t",$(NF -1)}' /etc/passwd|sed 's#$#\n------------------------------------------------------------------------#g'
List of users has Root access
$ awk -F: '{ print $1,"   \t" $NF,"   \t",$(NF -1)}' /etc/passwd|grep "/bin/bash"
List of user don't have login access
$ awk -F: '{ print $1,"   \t" $NF,"   \t",$(NF -1)}' /etc/passwd|grep "nologin"
How to Add, Remove and Modify Users in Linux
$ sudo adduser newusername
or
$ sudo useradd -m newusername
Add user without password
$ sudo adduser --disabled-password --gecos "" USERNAME
Remove password from existing user account and disable it untill add new password from sudo user
$ passwd -d linuxtechi
Rename user
$ sudo usermod -l new-user-name old-user-name
View users UID using command
$ id -u newusername 
PID for all the groups for efx
$ id efx
To change UID of user efxx
$ usermod -u [New-user-id] [username]
View all PID (process id) for programs
$ ps -u efxx
Add user in sudo user
$ sudo usermod -aG sudo username
Kill the process other user process
$ pkill -u username 1532
Kill all the process owned by the user
$ pkill -9 -u username
Delete a User in Linux
$ sudo deluser username
or
$ sudo userdel username
Delete user with files
$ sudo userdel -r username
Change user password
$ passwd username
Create and modify a Group in Linux
Create a new group (view the group file /etc/groups)
$ sudo addgroup groupname
or
$ sudo groupadd groupname
Assign a password to group
$ sudo gpasswd groupname
View all the group list
$ getent group
Delete the group with group name
$ sudo delgroup groupname
or
$ sudo groupdel groupname
Check list of user Groups in Linux
To check a user group
$ groups efxx
Check owner groups
$ groups
Add a User to a Group in Linux(postgress service to sudo group)
$ usermod -aG postgres efxx
Remove a User from a Group in Linux
$ gpasswd -d efxx postgres
Remove user form specific group
$ sudo deluser efxx postgres
Must check related posts...