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:
#!/bin/bash echo "Hello $USER!"
Note: The following commands would need to be run either as the root user, or using the
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
cp /path/to/hello.sh /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/hello.sh
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/hello.sh
To allow anyone to be able to run the script, set the script’s permissiosn to 755:
chmod 755 /usr/local/bin/hello.sh
Now users will be able to run the script simply by running
$ hello.sh 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