Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1163
  • Last Modified:

Permission Denied while running a bash script via cron on MNT/NAS, How to solve this?

Hello,

I have nas setup on my hosting server and doing great running my bash script via root with putty connection.
Whenever I try to run these bash script that basically does "ls" on the nas folder and copies mysqldump *.gz to it - I get a permission denied error.
this doesn't occur when running the script with root.

I have tried for hours to get around this, cron runs the bash script under it's cpanel username in this case, which I guess doesn't have root's permissions - Can you please help me in how can get my user to make modifications to the nas files?
this was my mount command:

mount -t cifs -o username=hiddenusername,password=hiddenpassword //hiddenIP/nas.nas.XXX /mnt/nas
(parts of the command were hidden for security reasons)

this is an example output of the script while running from my cpanel user's cron:
/home/XXX/mybackup.sh: line 5: /mnt/nas/backups/XXX/XXX_04_11_09.gz: Permission denied
mysqldump: Got errno 32 on write
ls: /mnt/nas/backups/XXX/XXX_04_11_09.gz: Permission denied
ls: /mnt/nas/backups/XXX/XXX*: Permission denied
(parts of the command were hidden for security reasons)

I have noticed that whitin the NAS my group name and username for files and folders are different and labeled as numbers.
Please provide help in which my cpanel cron user can make file modifications to that nas folder ?
0
tzvish
Asked:
tzvish
  • 5
  • 3
2 Solutions
 
Morne LateganCommented:
Hi there,

mount -t cifs -o username=hiddenusername,password=hiddenpassword,uid=your_linux_user,gid=your_linux_group,file_mode=700,dir_mode=700 //hiddenIP/nas.nas.XXX /mnt/nas

(Add the local user and group)
0
 
tzvishAuthor Commented:
Thanks, trying this out, any idea how this can be made for multipule users?
( i have about 6 cpanel account i want to set the cron commands to)
0
 
tzvishAuthor Commented:
Thanks, this worked great for my test cpanel user,

I got these 2 warnings:
WARNING: 'file_mode' not expressed in octal.
WARNING: 'dir_mode' not expressed in octal.


and i still don't know, how can i set it so the 5 other cpanel created users can is this ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tzvishAuthor Commented:
Cant get this to work for all my users, if i set the uid and gid for that current user they can modify files but then other users can't -
there must be a way to find a cummon permission setting for all these cpanel users, i tried to use root/root but that failed :(

any ideas?
0
 
ewest02Commented:
If you create the mount point as root, open the perms for the other non-root users,
   dir_mode=0755 file_mode=0755

Alternatively, create a mount point for each user. /mnt/nas/jdoe, /mnt/nas/mmouse, ...

Prepend a 0 (zero) to the mode values to remove those warning messages 700 -> 0700
0
 
Morne LateganCommented:
Oops, sorry, ewest02 is right, prepend the zero :)

Make sure all the users belong to the same group, then use 0770, that is: binary 111111000, or in Linux terms, rwxrwx--- which says that the linux user you mounted it as has read, write and execute permissions, the group you mounted it as has read, write and execute permissions and the rest has nothing.
0
 
tzvishAuthor Commented:
Hi, thanks - I cant get my nas folder to be 0755  - thus making "others" write files on it.
even when mounting with 0755 for dir and file, when using ls -l i get this:

drwxrws---+  3 root root    0 Apr 11 15:32 nas/

any idea why ?
0
 
Morne LateganCommented:
0755 = rwxr-xr-x

That means no write for the others. Try 0777 if you want "other" to have write permissions. Also, have a look inside the nas folder instead of at the nas folder, that is:

cd /path/to/nas
ls -l

Then do:

umount /path/to/nas
chmod 777 /path/to/nas

And then mount it again.
0
 
tzvishAuthor Commented:
Created a diffrent mounted folder for each of the cpanel users, and now it works great
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now