User Management in Linux

Commands used to Manage Users and Groups in Linux operating system

ยท

3 min read

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
SyntaxDescription
suLogin as root user
su -l-l stands for login shell for that user

image.png

2. id Command

id is the command used to identify the user information the command gives output as groups, gid, uid, SELinux context

SyntaxDescription
id -g user_namegives the group number
id -G user_nameto get group number along with secondary group membership
id -Gn user_nameto get the name of the group along with secondary group membership

image.png

3. useradd Command

useradd is used to create users in Linux

[root@server1 ~] useradd [options] <username>
SyntaxDescription
useradd -m user_namecreate the user home directory
useradd -N user_nameNo private group
useradd -d user_nameto specify the directory path
useradd -g user_nameto specify primary group
useradd -G user_nameto specify Secondary group
useradd -s user_nameto specify shell
useradd -Dto get default options
useradd -Ds /bin/shchanging 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 image.png

5. chage Command

chage is a command used to change the password age

SyntaxDescription
chage -l usernameto list password details
chage -M [number] usernameto change password expiry days

image.png

image.png

6. usermod Command

usermod command is used to modify the user

SyntaxDescription
usermod -c "fullname" usernameto modify user fullname
usermod -s /bin/sh usernameto modify user shell

image.png

7. chsh Command

chsh is used to manage shell

SyntaxDescription
chsh -lto list all the shells
chsh -s /bin/sh usernameto change shell of user

image.png

8. userdel Command

userdel is used to delete the user

To delete user and its home directory

[root@server1 ~] userdel -r username

image.png image.png image.png

9. newgrp Command

newgrp command is used to switch to different group id

[root@server1 ~] newgrp groupname

image.png

10. groupadd Command

groupadd is the command used to create a new group

[root@server1 ~] groupadd groupname

image.png

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 image.png

15. whoami Command

whoami to check current user image.png

Thank you for reading!!

Source/References doc

ย