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

  • 1
    The question is not completely clear: "your are root and want to run the script as user1" or "you are user1 and want to run the script as root"? If the first is the case, what is the problem with the sudo command you wrote?
    – michas
    Mar 5, 2014 at 22:22
  • Check out su(1)
    – vonbrand
    Mar 6, 2014 at 0:25

3 Answers 3


I must say I never liked sudo (especially its configurations). Plain old su:

su -c 'command' - user

Executed from root, it won't prompt for password.


The user must have

  1. execute permission for the whole directory path (here /root only)

  2. execute permission for the file

  3. 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 (chmod) to 770 and add user1 with ACLs (setfacl).


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.

Your /etc/sudoers entry will look like

Cmnd_Alias SCRIPT=/root/script.sh

# user who is allowed executing /root/script.sh
%user ALL = (ALL) SCRIPT

You normally would edit the file with visudo

You then also don't need to put -u root to your sudo command.

The % 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.

Not the answer you're looking for? Browse other questions tagged .