User Management in Linux
Commands used to Manage Users and Groups in Linux operating system
Hi everyone!
In this post, I will tell some useful commands to manage users and groups in Linux, managing users is very important in order to protect the system and data. Also, it makes it easy to monitor specific user activity.
1. su Command
su is a command used to switch user
[root@server1 ~] su [options] user_name
Syntax | Description |
su | Login as root user |
su -l | -l stands for login shell for that user |
2. id Command
id is the command used to identify the user information the command gives output as groups, gid, uid, SELinux context
Syntax | Description |
id -g user_name | gives the group number |
id -G user_name | to get group number along with secondary group membership |
id -Gn user_name | to get the name of the group along with secondary group membership |
3. useradd Command
useradd is used to create users in Linux
[root@server1 ~] useradd [options] <username>
Syntax | Description |
useradd -m user_name | create the user home directory |
useradd -N user_name | No private group |
useradd -d user_name | to specify the directory path |
useradd -g user_name | to specify primary group |
useradd -G user_name | to specify Secondary group |
useradd -s user_name | to specify shell |
useradd -D | to get default options |
useradd -Ds /bin/sh | changing default shell to sh |
[root@server1 ~] useradd -m user1
[root@server1 ~] useradd -N user2 -g users -G adm
[root@server1 ~] useradd user3 -G adm -s /bin/sh
4. passwd Command
passwd command is used to change the password of a user
5. chage Command
chage is a command used to change the password age
Syntax | Description |
chage -l username | to list password details |
chage -M [number] username | to change password expiry days |
6. usermod Command
usermod command is used to modify the user
Syntax | Description |
usermod -c "fullname" username | to modify user fullname |
usermod -s /bin/sh username | to modify user shell |
7. chsh Command
chsh is used to manage shell
Syntax | Description |
chsh -l | to list all the shells |
chsh -s /bin/sh username | to change shell of user |
8. userdel Command
userdel is used to delete the user
To delete user and its home directory
[root@server1 ~] userdel -r username
9. newgrp Command
newgrp command is used to switch to different group id
[root@server1 ~] newgrp groupname
10. groupadd Command
groupadd is the command used to create a new group
[root@server1 ~] groupadd groupname
11. chgrp Command
chgrp is used to change the group permission of a specific folder or directory
[root@server1 ~] chgrp -R groupname file/folder
12. chmod Command
chmod is used to modify the specific permission
- o: other users
- u: user
- g: group
[root@server1 ~] chmod -R o= file/folder
[root@server1 ~] chmod g+s file/folder
13. chown Command
chown is used to change the ownership of a specific folder or directory
[root@server1 ~] chown ownername file/folder
14. who Command
who is used to check all users logged in
15. whoami Command
whoami to check current user
Thank you for reading!!
Source/References doc