Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 6, 2019 04:54 am GMT

Understanding Linux Permissions

Table of contents

Introduction

The multi-user capability of Unix-like systems is a feature that is deeply ingrained into the design of the operating system.

File Permissions

On a Linux system, each file and directory is assigned access rights for the owner of the file.

You can check the permission settings by using ls -l.

$ ls -l drwxr-xr-x. 13 root  root  1027 Jan  3 12:32 bin/cat

Let's explore what drwxr-xr-x. 13 root root 1077 Jan 3 12:32 bin/cat means one by one.

CommandMeaning
dFile Type
rwxr-xr-x.File Mode
13Number of links
rootThe owner of the file
rootThe group the file belongs to
1027Size of the file
Jan3 12:32Time Stamp
bin/catThe name of the file/directory

File Type

CommandFile Type
-File
dDirectory
lSymbolic Link

File Mode

The r letter means the user has permission to read the file/directory. The w letter the user has permission to write the file/directory. And the e letter means the user has permission to execute the file/directory.

CommandMeaning
rread
wwrite
xexecute
-not allowed

Let's take a look at the 9 letters in the command.
The first 3 letters show the permissions for the file owner, the second 3 letters show the permissions for the group owner and the last 3 letters show the permissions for other users.

rwx/ r-x/ r-x/Owner: rwxGroup: r-xUsers: r-x

Change File Modes

The chmod command is used to change the permissions of a file or directory.

Octal Mode

Each permission may be specified with an octal number: read = 4; write = 2; execute = 1; no permission = 0.

MeaningNumber
read(r)4
write(w)2
execute(x)1

Example

The command below means giving permissions to read(4), write(2) and execute(1) to the owner and permissions to read(4) and execute(1) to the group user and permissions to read(4) to other users.

chmod 754 myfile

Symbolic Mode

The blow is the basic syntax of chmod.

% chmod who operator permission filename

You can use the following commands to change modes.

CommandMeaning
u(user)user access
g(group)group access
o(other)other access
a(all)user, group, and other access
CommandMeaning
+add specified permissions
-remove specified permissions
=set the specified permissions

Example

In the following example, read permission are taken away from others.

% chmod o-r filea

In the following example, read and execute permissions are added for user, group, and others.

$ chmod a+rx fileb

In the following example, read, write, and execute permissions are assigned to the group.

$ chmod g=rwx filec

References


Original Link: https://dev.to/ksato1995/understanding-linux-permissions-397e

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To