I need to make a backup and then alter a file owned by ‘root’ when installing my app in a site.
I have tried running …
sudo bench --site dev.erpnext.host install-app myApp
… but I get a PermissionError just the same.
I know that this is possible:
try:
shutil.copy(file1,destination)
except PermissionError:
shutil.os.system('sudo cp "{}" "{}"'.format(file1,destination))
I’m just wondering if there’s something better…
Cool! Thanks!
Posting a question often leads me to think differently about the root problem.
The file I need to alter is within NGinx. Running NGinx as root is a security hole!!
So, just now, I created an nginx
non-privileged (non-sudo) user and group, added my ERPNext user to that group and enabled group write privileges on the parent directory, and … IT DID NOT WORK!!!
Then after being a moron for 10 minutes I logged out and back in again … and then it did work.
End result … no need for sudo in my install hook.
2 Likes
If I had a dollar for every time I forgot to logout+login after adding a user to a group…
…I would have lots and lots of dollars.
1 Like
if you don’t wish to logout then use newgrp
command.
example:
newgrp nginx
2 Likes
Sounds like the basis for an alt-coin project … interested?
1 Like