From root user, how can I give permissions to another user to execute the file /root/script.sh ?
The idea is to run the script like
sudo -u user1 /root/script.sh
The user must have
execute permission for the whole directory path (here
execute permission for the file
read permission for the file
It may be a good idea to leave
/root untouched and create (or use) a different directory for this purpose (e.g.
/usr/local/bin). You can make
user1 the only user who is allowed to execute the script by making it the owner of the file or leave
root as owner and group, set the simple access permissions (
770 and add
user1 with ACLs (
If your script is located in the root dir, then
$ LC_ALL=C ls -ld /root
drwx------ 17 root root 4096 Mar 5 20:14 /root
user1 can only be root.
/etc/sudoers entry will look like
# user who is allowed executing /root/script.sh
%user ALL = (ALL) SCRIPT
You normally would edit the file with
You then also don't need to put
-u root to your
% means the user group. When you leave it out then only the user is allowed to execute the command. If you want a group of users to execute it, then leave like it is.