0

I have the following simple script that changed ownership on folders

more hola_config.sh

#!/bin/bash

chown -R hola:pola /home/darna
chmod -R 775  /home/darna

in /etc/sudoers I added the following ( super_hola user is like super user )

super_hola ALL=(ALL)       NOPASSWD:ALL 

but when I run the script as

su super_hola
whoami
super_hola

sudo -u super_hola ./hola_config.sh

I get Operation not permitted from chmod from the script

Example:

chmod: changing permissions of ‘/home/darna/linux.cvg: Operation not permitted

the question is

why the super user as super_hola can't change the permission like root user and what to fix in my configuration in order to enable user – super_hola to do so

here the user and group IDs

id super_hola
uid=1001(super_hola) gid=1001(pola) groups=1001(pola),982(docker)

grep super_hola /etc/group
docker:x:982:super_hola

id -G super_hola
1001 982
9
  • What user do you run sudo as (and what are the sudoers rules for that user)? Is the super_hola user a user with UID=0? Commented Jan 9 at 7:24
  • I update the post with your request (let me know if you need more details -:) ) Commented Jan 9 at 8:31
  • And what user is executing the sudo command? It appears that you try to change the identity of the current user to super_hola, not that you try to change from super_hola to root. Commented Jan 9 at 8:59
  • Why would root want to do that? The root user would be able to run the script directly. Commented Jan 9 at 9:04
  • 1
    Well, if you want to change ownerships of files, you must run the script as root. From root, that would be done with ./fix_perm.sh. From the other user, it would be done with sudo ./fix_perm.sh. There is no point to becoming super_hola if you are already root, and there is no point to running the script as super_hola using sudo -u super_hola. Commented Jan 9 at 9:13

1 Answer 1

1

If you want to change ownership of files or permissions for files you don't own, you must run the script as the root user.

As the root user, the script would be run with ./hola_config.sh.

As the super_hola user, it would be run with sudo ./hola_config.sh.

If you are already root, there is no point in becoming super_hola.

There is no point in running the script as super_hola using sudo -u super_hola ./hola_config.sh, as you are already that user (and that user does not have permission to make the necessary changes anyway).

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.