I've designed a Python script that creates a SQLite database and needs to store it somewhere. This script has no need in escalated privileges, however, it needs to store its data somewhere so that it is accessible to all the users because the data is user-independent (but can be changed by every user). /var/lib doesn't do because it's owned by root and an ordinary user cannot create or put something in there. /usr/share, as I know, is designed to store data that doesn't change. So - what do I choose?
Asked
Active
Viewed 107 times
1 Answers
1
A user with escalated privileges can create the database in a privileged location, and then set the file permissions to the database to something less restrictive. For instance:
sudo touch /var/lib/my_shared_db.sqlite3
sudo chmod 666 /var/lib/my_shared_db.sqlite3
After this any user will be able to write to /var/lib/my_shared_db.sqlite3
. (Note: it's probably better to create a directory in /var/lib
named after your script and then put the db file(s) in it.)

Amber
- 507,862
- 82
- 626
- 550
-
Yeah, I know that directory stuff and that's exactly what I'm trying to do. But maybe there's another place? – Арсений Пичугин Nov 06 '13 at 02:41
-
The only place that isn't specific to a particular user but also is writable by all users, on most Linux distributions, is `/tmp` (or `/var/tmp`) - and you don't really want to put things like databases there. – Amber Nov 06 '13 at 03:08
-
Well... Finally I've modified my program so that it needs root privileges when run for first time, then it creates the directory needed and sets the permissions, and no more running as root is needed. Thank you very much, dear Fluttershy! ;-) – Арсений Пичугин Nov 06 '13 at 04:20