Table of contents
Welcome to the part 2 of Journey to become Linux Wizard Part 1
User Management
User & Groups
- User ID [UID] use to identify user
- Group ID [GID] use to identify groups
- Other users like System Daemon, Root user/Superuser, etc.
Root User
- User who has complete access to the system.
- Its UID is 0.
- use
sudo
command to execute the command as the root user. sudo su
command to become a root user.- command you use as a root user, their history will not be saved so use them carefully.
Who are these other users in system other than me and root?
sudo cat /etc/passwd
to see a list of all users,
you'll find a lot of users but lets focus on first one to understand all this gibberish,
- 'root' is the username.
- 'x' is the password for the user, which is encrypted .and stored in
/etc/shadow
- '0' is the User ID.
- '0' is Group ID.
- User info which is the root user in our case.
- user's home directory.
/bin/bash
is the User's Shell.
/etc/shadow
type the following command to see the password details of users
- 'root' is the username.
- '!' is an encrypted password.
- '19056' is the date of the last password change since 1st Jan. 1970.
- '0' is the Minimum password age.
- '99999' is the Maximum password age.
- '7' is the warning period to change the password.
- ':' is the password expiry period.
- ':' is the Account expiration Date.
- ':' is Reserved Field.
/etc/group
type the command
- 'root' is the group name.
- 'x' is the group password.
- '0' is the group ID.
- Last empty field is the list of users in this group.
How to create & delete a user?
sudo useradd nameofuser
sudo userdel nameofuser
How to change password and hostname?
sudo passwd userName
sudo hostname newUser
Permissions
Types
- Read (r)
- Write (w)
- Execute (e)
type the following command
ls -l
start with the gibberish on the left side
drwxrwxr-x
Understand this by dividing it into four separate parts.
- Tells about type
- d is a directory
- '-' is a file
- l is a link
rwx
are user permissions.rwx
are group permissions.r-x
are others' permission.
so, what is this 'rwx' and 'r-x' means ?
r
is readability permissionw
is writability permissionx
is executability permission-
empty
so in the above photo, the user and group have all permissions to read, write and execute the directory but other users only have permission to read and execute
Modifying Permissions
let say i have a file named myfile.txt with permission -rw-rw-r--
change permission using chmod
command
$ chmod o+w myfile.txt
o
is for other users
w
is to give it writing permission
+
is to add permission
-
is to remove permission
Modifying Multiple Permissions
$ chmod ugo-rwx myfile.txt
ugo
is for user, group & others-
is to remove permissionrwx
is read, write and execution permission- we removed all three permissions for three kind of users
Numerical representation of permissions
- read (r)
4
- write(w)
2
- execute(x)
1
to grant all permission by using numerical representation
$ chmod +777 myfile.txt
+
to add permission7
to add all permission to user7
to add all permission to group7
to add all permission to other users
Numerical presentation
0
No permission1
execution permission2
write permission3
write and execution permission4
read permission5
read and execution permission6
read and write permission7
read, write and execution permission
Change user ownership of file
$ sudo chown pintu myfile.txt
so ownership will transfer to the username pintu
Change group of file
$ sudo chgrp
Set User ID (SUID)
lets type a command in your terminal
$ ls -l /usr/bin/passwd
How am i able to access this data without being root user?
you can see its permission, lets break down it to understand it better
rwsr-xr-x
we have an s
in user permission,
s
is SUID which give us ownership and execution permission.
S
will only give only ownership
Add SUID to user
$ sudo chmod u+s myfile.txt
- add permission to user
$ sudo chmod 4755 myfile.txt
4
is for SUID
Add Group ID (GUID)
$ sudo chmod 2755 myfile.txt
2
for GUID
Sticky Bit Permission
- It grants all permission but only delete access is only for user
type the command ls -ld/tmp
you will see
drwxrwxrwt
t
is Sticky Bit
Modify Sticky Bit
$ sudo chmod +t directory
$ sudo chmod 1755 directory
1
for sticky bit permission
See you in the next blog of Linux Process