LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Setting file and script permissions (https://www.linuxquestions.org/questions/linux-newbie-8/setting-file-and-script-permissions-759784/)

Jeroen1000 10-05-2009 05:32 AM

Setting file and script permissions
 
Hi everyone,

This one is still a little too hard to get my head around.

I've got a root script which (depending on a certain condition) decides whether or not to call a backup script.

This backup script needs to run with user privileges, and not with root privileges. The backup script will call the rsync deamon and will write files to the users backup directory. So the owner of the backup directory will be the one that calls the backup script with his/her user privileges.

The root script does a chown of backup directory and then I execute a su to the correct user just before executing the backup script.
I've been experimenting with chown but that does not allow the back up script to delete or add stuff.

Simply said, I don't know which commands to run to accomplish this task.

Any help is more than welcome:newbie:

Jeroen1000 10-05-2009 06:09 AM

when I switch to the user (terminal window) who should be able to access his folder, I keep getting
cd: 2: can't cd to jeroen. I did a chown user:user and chmod 777 but to no avail. What am I missing here?

below is the output from ls -l the user 'jeroen' should be able to access his directory, also called 'jeroen'

Code:

drwxrwxrwx 7 jeroen jeroen 4096 2009-10-05 12:37 jeroen

SharpyWarpy 10-05-2009 06:12 AM

Did you try running:
chmod 7666 on the dir?

Jeroen1000 10-05-2009 06:21 AM

Quote:

Originally Posted by SharpyWarpy (Post 3708209)
Did you try running:
chmod 7666 on the dir?

Still no dice. Now it says

Code:

drwsrwsrwT 7 jeroen jeroen 4096 2009-10-05 12:37 jeroen
I've noticed I am able to ls when I'm in the dir jeroen. I just can cd to the directory. Or is this because the directory jeroen is a subdirectory of /root?

jschiwal 10-05-2009 06:42 AM

Don't use /root to contain users' backups. You should use it in only very rare occasions.
A user needs read and execute writes to the parent directory to save files in /root/. You don't want that.

A network NAS or external drive would make more sense. If your computer's drive becomes damaged, your backup and the original documents are on the same machine. Rsync can clone the permissions of files when copying them. Using su isn't necessary unless your reason is that you don't want your cron job running as root.

lutusp 10-05-2009 10:36 AM

Quote:

Originally Posted by Jeroen1000 (Post 3708217)
Or is this because the directory jeroen is a subdirectory of /root?

Yes, that's the reason. Remember that in order to list or access files in a particular directory, that directory, plus all parent directories, must be accessible to the user in question.

The only reason that normal users have access to their own files under /home is because /home has these permissions:

Code:

drwxr-xr-x /home
And the only reason /home is accessible is because the system root directory has these permissions:

Code:

drwxr-xr-x /
(on a directory, "execute" permissions grant access)

Think of it as a set of doors to an inner sanctum -- you have to be able to pass through each door before accessing the treasure.

catkin 10-05-2009 10:44 AM

Quote:

Originally Posted by lutusp (Post 3708418)
Think of it as a set of doors to an inner sanctum -- you have to be able to pass through each door before accessing the treasure.

That's a great new perspective on the contents of /root :twocents::twocents::twocents:


All times are GMT -5. The time now is 07:11 AM.