Users and Groups in Linux
- Linux is a multi user operating system.
- To add a new user account, we have two commands
- adduser
- useradd
- Generally whenever a user is created, User gets
- username
- uid
- home directory
- A group is created for the user with the same name as username
- Difference between useradd and adduser
adduser test1
useradd test2
cat /etc/passwd
ls /home
- Lets look at redhat
- we can set the password to the user by executing
passwd
- In the home directory, few hidden files are created
- If you look into /etc/passwd the entry pattern in this file looks as
[username]:[x]:[UID]:[GID]:[COMMENT]:[HOMEDIRECTORY]:[Defaultshell]
# ubuntu entries
test1:x:1001:1001:,,,:/home/test1:/bin/bash
test2:x:1002:1002::/home/test2:/bin/sh
- If you look into /etc/group file, the format for each line
[Group name]:[Group password]:[Gid]:[Group members]
# sample ubuntu entries
test1:x:1001:
test2:x:1002:
- For group management
groupadd
groupdel
usermod
-
Exercise:
- Create a user called as ironman
- Create a user called as thor
- Create a user called as hulk
- create a user called as superman
- Create a user called as batman
- Create a user called as wonderwoman
- create a group called as Avengers and add ironman, thor and hulk to it
- Create a group called as JusticeLeague and add superman, batman and wonderwoman.
- Some screenshots
-
How can i give sudo permissions to my users
- In ubunutu we have a group called sudo, if you add users to this sudo group, then can execute sudo commands.
- In RHEL family, we have a group called as wheel, adding users to this wheel group can enable users to execute sudo commands
-
Adding a user ironman to sudo group