Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

closed as unclear what you're asking by Gilles, slm, jasonwryan, Hauke Laging, Karlson Mar 6 at 1:15

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

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 at 22:22
    
Check out su(1) –  vonbrand Mar 6 at 0:25
add comment

3 Answers 3

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).

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.