Create a file in /etc/ as a non-root user

Alister alister.ware at ntlworld.com
Fri May 31 10:02:36 EDT 2013


On Fri, 31 May 2013 07:11:58 -0400, Dave Angel wrote:

> On 05/31/2013 05:27 AM, Luca Cerone wrote:
>>> fd = open('/etc/file','w')
>>>
>>> fd.write('jpdas')
>>>
>>> fd.close()
>>>
>>>
>> Hi Bibhu, that is not a Python problem, but a permission one.
>> You should configure the permissions so that you have write access to
>> the folder.
>> However unless you know what you are doing it is discouraged to save
>> your file in the /etc/ folder.
>>
>> I don't know if on Mac the commands are the same, but in Unix systems
>> (that I guess Mac is) you can manage permissions with chmod.
>>
>>
> That directory is protected from users for a reason.  You defeat that
> and risk the system.
> 
> Bibhu:  for that reason I'd suggest simply telling your users to run
> your script as root.  If they trust you, and it breaks something, at
> least they know why they were doing it.
> 
>     sudo  python  riskyscript.py

Bibhu without wishing to seem rude, the fact that you had to ask this 
question indicates that you almost certainly should not be writing to 
this directory.

/etc is used to store configuration files for the operating system & if 
you inadvertently corrupt the wrong one then you could kill the system.

if you can provide more details regarding what you are actually trying to 
achieve you may get some better answers & will almost certainly save 
yourself a whole heap of pain


-- 
It is not for me to attempt to fathom the inscrutable workings of 
Providence.
		-- The Earl of Birkenhead



More information about the Python-list mailing list