Post

Day 4 of 100 Days of Devops

Script Execution Permissions

Day 4 of 100 Days of Devops

The Requirement is as follow

In a bid to automate backup processes, the xFusionCorp Industries sysadmin team has developed a new bash script named xfusioncorp.sh. While the script has been distributed to all necessary servers, it lacks executable permissions on App Server 1 within the Stratos Datacenter.

Your task is to grant executable permissions to the /tmp/xfusioncorp.sh script on App Server 1. Additionally, ensure that all users have the capability to execute it.

So as usual just go in to the app server mentioned via bastion.

1
2
3
4
[tony@stapp01 tmp]$ ls -l xfusioncorp.sh
---------- 1 root root   40 Nov 27 22:28 xfusioncorp.sh

We can see ——— line on our file that means the script has no permission.

In order to make the script executable is totally fine but there is another requirement we need to make sure all users have the capability to execute it. Which make me think of how chmod works in linux.

TLDR;

1
2
3
chmod 755 xfusioncorp.sh # Numeric Mode

chmod a+x xfusioncorp.sh # Symbolic Mode

CHMOD

The chmod command (short for change mode) is a fundamental Linux utility used to modify the permissions (access rights) of files and directories. These permissions determine who can read, write, or execute a file or traverse a directory. Permissions are managed for three categories of users:

User (u): The file’s owner.

Group (g): Members of the file’s associated group.

Others (o): All other users on the system.

You can modify permissions using two main methods: symbolic (text) mode and numeric (octal) mode.

1. Symbolic Mode

Symbolic mode uses letters and symbols to add (+), remove (-), or set (=) specific permissions for specific user classes. Syntax: chmod [who][operator][permissions] filename

WhoOperatorPermissions Description
u, g, o, a (all)+, -, =r, w, x
User, Group, Others, or All usersAdd, Remove, or Set exactlyRead, Write, or Execute permission

Examples:

1
2
3
4
chmod u+x script.sh # Adds execute permission for the owner of script.sh.
chmod g-w file.txt # Removes write permission for the group of file.txt.
chmod o=r data.txt # Sets others' permission to only read, removing any other existing permissions for others.
chmod a+rw mydir # Adds read and write permissions for all users to mydir. 

2. Numeric Mode

Numeric mode uses a three-digit octal number (0-7) where each digit represents the permissions for the owner, group, and others, respectively. Each permission has a numerical value: Read (r): 4 Write (w): 2 Execute (x): 1 No permission (-): 0 Permissions for each category are calculated by summing the values.

ValuePermissionsSymbolic
0No permissions
1Execute–x
2Write-w-
3Write and execute-wx
4Readr–
5Read and executer-x
6Read and writerw-
7Read, write, and executerwx

Examples:

1
2
3
chmod 755 filename # Sets permissions to rwxr-xr-x (owner has full access; group and others can read and execute). This is a common permission for executable files and directories.
chmod 644 filename # Sets permissions to rw-r--r-- (owner can read/write; group and others can only read). This is a common default for general files.
chmod 700 private_script.sh # Only the owner has full access; group and others have no permissions. 

Key Concepts

Viewing Permissions: Use the ` ls -l` command to see the current permissions of a file or directory.

Recursion: The -R option can be used to apply permission changes to all files and subdirectories within a given directory.

Example: chmod -R 755 mydir. Directories: For a directory, the ‘x’ (execute) permission means a user can enter (traverse) the directory, while ‘r’ allows listing its contents.

Security Risk: Using chmod 777 grants read, write, and execute permissions to everyone and is generally discouraged due to security vulnerabilities.

For more information please check your local non AI friend chmod --help and also go and visit the official documentation.

https://www.gnu.org/software/coreutils/chmod

Thats all of today , Thx Bye !

This post is licensed under CC BY 4.0 by the author.