import os # Creating a new user account os.system("sudo useradd -m -s /bin/bash newuser") # Deleting a user account os.system("sudo userdel -r olduser")
import pwd # Retrieving user account information user = pwd.getpwnam("username") print(user.pw_uid) # prints the user ID # Modifying user account information pwd.setpwent() # reset the password database pwd.struct_passwd.pw_shell = "/bin/sh" pwd.endpwent() # close the password database
import win32net # Creating a new user account user_info = { 'name': 'new_user', 'password': 'password', 'priv': win32net.USER_PRIV_USER, 'home_dir': '\\\\SERVER\\UserShares\\new_user', 'comment': 'A new user account' } win32net.NetUserAdd(None, 1, user_info) # Adding a user to a group win32net.NetLocalGroupAddMembers(None, 'Administrators', 3, [{'name': 'new_user'}])