Search results for:
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. You need to put the script into a location all users have access to and set the script permissions to allow reading and execution by the users you want running the script.
For this guide, let's have an example script called hello.sh, that 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 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/hello.sh /usr/local/bin
Second: Optionally, you can then change ownership of the file to limit who can run this script more securely. For example, you can change the file owner 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 ownership 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 permissions to 755:
chmod 755 /usr/local/bin/hello.sh
Now users will be able to run the script simply by running hello.sh:
hello.sh Hello user!
Written by David Hamilton / September 24, 2019