Jump to content

Setting User and Group Permissions for executing programs in Linux


Recommended Posts

Posted (edited)

Eg:

id user1 (or) id -u user1

 

Association of UID / GID with Programs:

Whenever a user or group runs a program in Linux, they should have the permission to execute the program or else they are not allowed to execute the program. In order to make the program executable under this user account, the user need to set the Sticky bit which is called SUID (SetUserID) or SGID (SetGroupID).

Although this can be done by using Graphical User Interface, here we show you the way of how to achieve this in terminal which is very easy and faster.

Checking permission for files:

Step 1: To find ‘ What is existing permission for a file or directory ? ‘, supply this command in your terminal:

 

# ls -l
 
 

 

 

this command will display the permission for all the files in a directory.

Step 2: To find the permission for a specific file

 

# ls -l filename
 
 

 

 

replace the filename with the respective name of the file that you want to check.

The above commands specified will return something like ‘ drwxr-xr-x ‘. where,

d- directory.

r-read, w-write, x-executable.

If x is missing then it means, the file or program has not got the executable permission.

To Set Permission for files or Programs:

‘ chmod ‘ is the command used to achieve the task.

 

chmod changes the file mode bits of each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.

 

chmod preserves a directory’s set-user-ID and set-group-ID bits unless you explicitly specify otherwise. You can set or clear the bits with symbolic modes like u+s and g-s, and you can set (but not clear) the bits with a numeric mode.

Step 1:

 

# chmod u+s filename
 
 

 

 

Note: Replace filename with the name of the file for which permission has to be set.

Here,

u – Associates of sets the user’s id as the owner of the file.

s – Sets the SUID; where g+s, sets the SGID.

 

Step 2: Now in order to check the changes we made, run the below command:

 

# ls -l filename
 
 

 

 

Step 3: Now you can run the program with desired and proper executable permission.

The chmod command has now changed the scenario, now after setting the permission for a program, the program will run with the Permissions that the user who runs the program have.

 

To know more about chmod command type: ‘ man chmod ‘ in your terminal.

Hence, you can check the permissions for the file and similarly you can disable permission for executing some files if you wish it lacks security. :)

Edited by Fearless News

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.