Jump to content

  • Log in with Facebook Log in with Twitter Log In with Steam Log In with Google Sign In
  • Create Account

Tutorial info Visit support topic

  • Added on: Feb 26 2013 05:16 AM
  • Date Updated: Feb 27 2013 07:14 AM
  • Views: 692
 


Setting User and Group Permissions for executing programs in Linux

Every User or group in a Linux or (Unix like) Operating system is associated with a unique identity called UserID (UID) for a user and GroupID(GID) for a group.
To know the uid, gid of your account simply type the ‘id’ command in your terminal.
To know the id of any user account, simply type ‘id username’. Replace username with corresponding username.

Posted by Jopa on Feb 26 2013 05:16 AM

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. :)