How Can We Help?

User Group and File permission in Linux

Table of Content

User and group:

User: In linux users are used to create security boundaries. By using we can differentiate permissions of files and folders. By humans users are identified by User Name but in system users are identified by UID (user id) .User ID Is a unique id of any user. There are three types of users in linux. All information about any user is stored in  /etc/passwd.

1) Super User (User ID: 0)

2) System User (User ID 1-999)

3) Regular User (User ID:1000-65536)

Groups: In linux groups are a collection of users and used to set security of files and folders.

There are two types of groups in linux. Groups are identified by GID (Group ID) in linux.

  1. Primary Group
  2. Secondary Group

Primary group is created by default at the time of user creation.

How to create User:

Useradd command is used to create the user

#useradd vikas

After adding the user please define user’s password otherwise user will not be able to access their account. To define the password use passwd command.

#passwd vikas

or you can set password by the below command as well

#echo “password@123@” | passwd --stdin vikas

All details of user users are stored in /etc/passwd file. There are seven fields in /etc/passwd file

Username:password:UID:GID:comment:home_directory:login_shell

Example:

vikas:x:1000:1000::/home/vikas/:/bin/bash

How to add group

#groupadd microhost

All details about any group are stored in /etc/group file the syntax of /etc/group file is 

groupname:password:GID:Member

File System Permission

ls command is used to list the file and directories on the Present working directory

[root@cent7 ~]# ls -l
total 4
-rw-------. 1 root root 1419 Feb  9  2022 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Aug 20 04:14 microhost

In this example owner of file microhost is root and group owner  of the file is also root

chown  command

chown command is used to change the ownership of file and directory

 In this example to change the ownership and group owner of file microhost

Syntax : =   chown  user_name:Group_owner  filename

#chown microhost:admin  microhost

Now file owner and group owner has been changed

 Permission

a   All                   r read           è     4

u  user                w  write        è     2

g  group              x execute     è     1

o others              + for add permission     - is used for removing permissions

In this example

Owner have  read and write permissions

Group owner and others  have read only permission

chmod  command is used to set permissions on file and directory

# chmod a+rwx microhost

This command will apply rwx permissions on owner ,group owner and others

# chmod  o+rwx microhost

This command will add  rwx  permissions on other users

Table of Contents