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

Chris Angelico rosuav at gmail.com
Fri May 31 10:42:13 EDT 2013


On Sat, Jun 1, 2013 at 12:02 AM, Alister <alister.ware at ntlworld.com> wrote:
> /etc is used to store configuration files for the operating system & if
> you inadvertently corrupt the wrong one then you could kill the system.

Expanding on this:

http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

The FHS applies to Linux, but you'll find it close to what other
Unix-like OSes use too.

It's extremely common to *read* config files from directories like
/etc, but to require root privileges to edit them. If you need to
store data files for some application that runs as your own user, one
good place is a dot-file or directory in your home directory - for
instance, I have:

/home/rosuav/.wine/
/home/rosuav/.bash_history
/home/rosuav/.ssh/
/home/rosuav/.SciTE.session

and many more. All of these are happily read/written by processes
running under the user 'rosuav' (my primary login user). If a
different user fires up bash, a different .bash_history will be used.
This system works well for users that represent humans.

The other type of user is the one that, well, doesn't represent a
human :) Figuring out where they can store files is a bit harder.
PostgreSQL gets itself a directory somewhere - maybe /opt/postgresql,
maybe /var/lib/postgresql - and restricts itself to that. But the
directory is created by root and then handed over (chowned) to the
other user.

Both these options work well; random processes editing stuff in /etc doesn't :)

ChrisA



More information about the Python-list mailing list