How do I switch to an admin-user account from this python script named root_and_user.py that was run with doas or sudo?
#!/usr/bin/env python3
from os import geteuid, seteuid
from subprocess import run
from sys import argv, exit
def touch(fname):
with open(fname, 'a') as f:
pass
#run this doas ./root_and_user.py
if geteuid() == 0:
touch("1.owned-by-root")
touch("2.owned-by-root")
seteuid(1000)
touch("1.owned-by-admin-user")
touch("2.owned-by-admin-user")
I've written my own custom function, also called touch() that creates an empty file. 1000 is the id of admin_user. When I run the script with sudo or doas the files 1.owned-by-admin-user and 2.owned-by-admin-user are created but they still belong to the group root - although being owned by admin_user. My aim is to accomplish that 1.owned-by-admin-user and 2.owned-by-admin-user are not only owned by admin_user but also have a group admin_user. How might I accomplish that?