MicroHost

MicroHost

Did You Know?

How Can We Help?

Special Offer

Deploy your Cloud Server now and get $100 in Free Credits!

Get Started

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

[console]#useradd vikas[/console]

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.

[console]#passwd vikas[/console]

or you can set password by the below command as well

[console]#echo “password@123@” | passwd --stdin vikas[/console]

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: [console]vikas:x:1000:1000::/home/vikas/:/bin/bash[/console]

How to add group

[console]#groupadd microhost[/console]

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

[console][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[/console]

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

[console]chown  command[/console]

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

 [console]#chown microhost:admin  microhost[/console]

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

[console]# chmod a+rwx microhost[/console]

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

[console]# chmod  o+rwx microhost[/console]

This command will add  rwx  permissions on other users

Special Offer

Deploy your Cloud Server now and get $100 in Free Credits!

Get Started
Table of Contents