Search The Hostwinds Guides Knowledge Base

How to Make a Script Executable to Other Users on Linux

Share This Article

If you have a Linux server with multiple users on it, there are some cases you have written a custom script/tool that you want to make available to other users. In order to do so, you simply need to put the script into a location all users have access to, and set the scripts permissions to allow reading and execution by the users you want running the script.

For this guide, let’s just have an example script called hello.sh, that simply says hello to the user that ran it:

Note: The following commands would need to be run either as the root user, or using the sudo command.

In nearly all Linux distributions, the directory /usr/local/bin is a location that can be used to make any executable files available to all users, as that directory is part of the user’s PATH.

First: Simply copy your script to /usr/local/bin:

Second: Optionally, you can then change ownership of the file to more securely limit who is able to run this script. For example, you can change the owner of the file to root, so that only root can edit the file, and can change the group for the file, to restrict being able to run the script to members of that group.

As an example, this changes the owernship to root, with the group ‘hello’:

Third: Change the file’s permissions to allow only the owner to edit it, and either its group or everyone to view and run it.

To allow only member’s of the ‘hello’ group specified in Step 2 to be able to run the file, set the script’s permissions to 750:

To allow anyone to be able to run the script, set the script’s permissiosn to 755:

Now users will be able to run the script simply by running hello.sh:

You can find more details on setting the ownership and permissions of files in Linux to suite your specific needs in this article:
Changing File Ownership And Permissions In Linux

Related Articles