Search The Hostwinds Guides Knowledge Base

How to Make a Script Executable to Other Users on Linux

Share This Article [TheChamp-Sharing]

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, that simply says hello to the user that ran it:

echo "Hello $USER!"

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:

cp /path/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’:

chown root:hello /usr/local/bin/

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:

chmod 750 /usr/local/bin/

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

chmod 755 /usr/local/bin/

Now users will be able to run the script simply by running

Hello user!

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