LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2010, 02:16 AM   #1
d!srupt!on
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Rep: Reputation: 0
file permissions


maybe this is trivial but i have been reading an intro to linux book and im confused on what exactly to do for this:

i want a certain file to set permission to r-x for any user, automatically, for any file saved into it.

basically im writing python scripts in gedit and saving to the afore mentioned file but when i try to run them in command line its says access denied. i know how to use chmod to change the permission singularly but its kind of a pain to have to log into root each time i make a new one.


im running ubuntu 9.10 karmic kola if it makes a difference
 
Old 02-06-2010, 02:46 AM   #2
bmxcess
Member
 
Registered: Jan 2009
Location: Brisbane, Australia
Distribution: @work:RHEL 5.4/Fedora 13, @home:slack64-current,ubuntu lynx studio
Posts: 65

Rep: Reputation: 19
There may be an easier way but you could write a script and run it with a root session:

Code:
#!/bin/bash
while [ true ]; do
        chmod +r+x /home/user/scripts/*.sh;
        sleep 5;
done;
Edit: make sure to specify the directory in the chmod command

Last edited by bmxcess; 02-06-2010 at 03:22 AM.
 
Old 02-06-2010, 04:09 AM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,927

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
You might also want to consider setfacl. This sounds promising to suit your needs:
http://www.linuxquestions.org/questi...folder-605129/

I could not set it up though. Maybe it's because of my ext2 FS. Let us know if you succeed.
 
Old 02-06-2010, 04:20 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
Quote:
i want a certain file to set permission to r-x for any user, automatically, for any file saved into it.
Could you rephrase this. You are saving files into a file?
Also, your post would be easier to read if you capitalized the beginning of sentences and the personal pronoun "I".

You can't prevent a copying a file using a users ownership and default permissions.

You can use a default facl on a directory to determine the facl's on files saved in the directory. You need to then also create an facl for the directory itself.

crts: According to the mount manpage, there is an acl option for ext2. You need to add the "acl" option to your mount options in /etc/fstab. Your kernel also needs the CONFIG_EXT2_FS_POSIX_ACL=y kernel option enabled.
 
Old 02-06-2010, 04:38 AM   #5
carbonfiber
Member
 
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46
Why do you have to log in as root?
 
Old 02-06-2010, 04:57 AM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,927

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
Quote:
Originally Posted by carbonfiber View Post
Why do you have to log in as root?
One reason I can think of is that maybe the containing parent directory does not have the execution-bit set. So it is not possible to change file permissions as normal user. Setting the execution-bit for the parent directory would solve this issue - if my guess is right.

But then again, why storing your executables in a non-eceutable directory in the first place?
 
Old 02-06-2010, 05:12 AM   #7
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 570

Rep: Reputation: 120Reputation: 120
Create a group, chgrp the directory to that group, add to the group the required members and then set the guid on the directory.
 
Old 02-06-2010, 09:42 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
This will set default permissions for a directory:
Code:
setfacl -m default:user::rx bin
setfacl -m default:group::0 bin
setfacl -m default:other::0 bin
This will give the user default rx permissions and deny access for other users.
Code:
> getfacl bin

# file: bin
# owner: jschiwal
# group: jschiwal
user::---
group::---
other::r-x
default:user::r-x
default:user:jschiwal:r-x
default:group::---
default:mask::r-x
default:other::---
It is normal to have a $HOME/bin/ directory in your path. If this is what you have in mind, you wouldn't need the default "group" and "other" rules, as other users don't have access to your HOME directory.
If you are the only owner for this directory (as in a directory in your HOME) then you could use:
setfacl -m d:u:<username>:rx <directory>

As I stated to crts, your kernel needs to support ACLs and the filesystem needs to be able to store the ACL attributes as well. The filesystem needs to be mounted with the ACL option.

----

Correction: The effective rights will be the union of permissions.

Last edited by jschiwal; 02-06-2010 at 10:08 AM.
 
Old 02-06-2010, 12:05 PM   #9
d!srupt!on
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
well i moved the file(directory) im saving scripts to into the bin file for python but the new txt files being saved there are still without execute permission. i tried the setfacl command and it said it was not supported.


Quote:
Originally Posted by bmxcess View Post
There may be an easier way but you could write a script and run it with a root session:

Code:
#!/bin/bash
while [ true ]; do
        chmod +r+x /home/user/scripts/*.sh;
        sleep 5;
done;
Edit: make sure to specify the directory in the chmod command
would this be persistent between power downs or would i have to run it everytime i log in?

there has got to be an easier way to make files saved into this dir to conform to the dir permission settings
 
Old 02-06-2010, 03:16 PM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,927

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
Quote:
Originally Posted by d!srupt!on View Post
well i moved the file(directory) im saving scripts to into the bin file for python but the new txt files being saved there are still without execute permission. i tried the setfacl command and it said it was not supported.
By default textfiles are created with perission 0666. It does not matter where you create them. If you want to change that you have to use ACL.
What filesystem are you using? Like me, you might have to edit the mount options in your /etc/fstab as suggested by jschiwal:

Quote:
According to the mount manpage, there is an acl option for ext2. You need to add the "acl" option to your mount options in /etc/fstab.
Your kernel also needs the CONFIG_EXT2_FS_POSIX_ACL=y kernel option enabled.
Quote:
Code:
#!/bin/bash
while [ true ]; do
        chmod +r+x /home/user/scripts/*.sh;
        sleep 5;
done;
would this be persistent between power downs or would i have to run it everytime i log in?
You would have to execute this script every time you open a terminal by running
Code:
./chmod_script &>/dev/null &
where chmod_script would be the name of the script. Alternativly you could edit your $HOME/.bashrc file and call the script from there. Also only files that end with the suffix *.sh would be affected, so you need to modify that as you deem necessary.
But you should try this only if you fail to setup ACL.

Last edited by crts; 02-06-2010 at 03:19 PM.
 
Old 02-06-2010, 03:43 PM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
According to the manpage of setfacl, the default x bit can only be set for directories. This is similar to no suid on directories or scripts.
Quote:
The perms field is a combination of characters that indicate the permissions: read (r), write (w), execute (x), execute only if the file is a directory or already
has execute permission for some user (X). Alternatively, the perms field can be an octal digit (0-7).
I had missed that and had never tried this usage.
You could use default acls to allow certain users to execute files copied there, but only if the x bit was already set.
 
Old 02-06-2010, 07:05 PM   #12
d!srupt!on
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post

crts: According to the mount manpage, there is an acl option for ext2. You need to add the "acl" option to your mount options in /etc/fstab. Your kernel also needs the CONFIG_EXT2_FS_POSIX_ACL=y kernel option enabled.
i tried "CONFIG_EXT2_FS_POSIX_ACL=y" in the command line which didn't give any message(error or otherwise) but when i tried to use the setfacl command it still said operation not supported.

supposing i did get acl to work, how would i change textfiles to default permission to 0733 instead of 0666?


also maybe using IDLE (python IDE) would be a better choice than making all textfiles executable?
*(maybe this should be another thread) the console said that python wasn't configured for Tk. I'll search around for a solution to this unless/until one pops up here

thank you for the help so far and i am still interested in getting ACL to work. I don't know what my file system is....whatever is standard on Ubuntu 9.10 i suppose
 
Old 02-06-2010, 07:31 PM   #13
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,927

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
Quote:
Originally Posted by d!srupt!on View Post
supposing i did get acl to work, how would i change textfiles to default permission to 0733 instead of 0666?
Hi,

I think I have a solution for this problem. As it appears it an not done with ACL. But you could install 'incrond'. This is a daemon that watches system events and reacts on them. I successfully installed and configured it. Here is a small HOWTO:

Open your package-manager (synaptic, since you are using ubuntu) and search for incrond. Choose to install it.

Next you will have to setup the configuration for incrond. You will need root privileges for that to work.
Code:
sudo su
echo 'root' >> /etc/incrond.allow
echo '<your normal user name>' >> /etc/incrond.allow
incrontab -e
The last command will open an editor. On my system it was GNU nano but this may differ on other systems. Type in the following:
Code:
path/to/directory/you/want/observed IN_CREATE chmod 774 $@/$#
Save and close the editor. Now you can start incrond
Code:
incrond
exit
That's it. You do not have to repeat the configuration every time. In the future you can just start incrond.
As normal user you will have to do this with
Code:
sudo incrond
To avoid the password prompt you could start the daemon during boot process.
 
Old 02-07-2010, 03:34 AM   #14
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
Quote:
i tried "CONFIG_EXT2_FS_POSIX_ACL=y" in the command line
That isn't a command. I was showing how to check whether your kernel is configured for ACL support, in part as an answer to crts about whether the ext2 filesystem supports ACLs. There are similar settings for each Linux filesystem. If it isn't set to Y or M, then you would need to enable these options and rebuild your kernel. I can't imagine your kernel having being built without ACL support.

Even if you don't have the 'x' bit set, you can execute scripts by calling the interpreter with the script as an argument.
E.G. bash ~/bin/sample.sh
python ~/pytonscripts/apythonscript.py

Besides, setting the x bit isn't hard using chmod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
changing default file permissions upon file creation ceci2 Linux - Newbie 7 10-01-2009 07:27 AM
File permissions v. directory permissions Completely Clueless Linux - Newbie 7 07-09-2009 08:33 AM
file permissions OK, but command permissions? stabu Linux - General 2 10-05-2005 12:00 PM
locking a usage policy file/ftp file permissions gbow Linux - Newbie 0 02-16-2004 05:35 AM
Changing file permissions on a SAMBA file share apenney Linux - Software 0 02-11-2002 04:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration