You should pass all args to subprocess.call
in separate elements of a list, try
subprocess.call(['useradd', '-c', comment, 'username', '-p', 'password'])
I replaced your password username
to 'password'
since '-p' argument to useradd
must be encripted with crypt
. Following snippet will help you with this:
import os
import crypt
import random
saltchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def salt():
return random.choice(saltchars) + random.choice(saltchars)
def encript_pwd(password):
return crypt.crypt(password,salt())
If you want password to equal username, use
subprocess.call(['useradd', '-c', comment, 'username', '-p',
encript_pwd(username)])