After testing the os , subprocess , getpass modules, I realized that the problem is not whether the user is installed. The user gets the set or changes with os.setuid , however methods from the modules to get the username, such as os.getlogin() , getpass.getuser() , do not actually get the username properly. If you run the whoami or id shell whoami using subprocess.Popen() or os.system() , you will get a modified user. For me this is a little puzzling. Below is a script that shows all these strange behaviors.
import os import subprocess import pwd import getpass
user966588
source share