How do I create a user in Linux using Python? I mean, I know about the subprocess module and thought about calling 'adduser' and passing all the parameters at once, but the 'adduser' command asks some questions like password, full name, phone and stuff. How would I answer this questions using subprocess? I've seen module called pexpect in this question: Can I use Python as a Bash replacement?. Is there any other standard module?
useradd is a command in Linux that is used to add user accounts to your system.
To create a user account from a shell prompt: Open a shell prompt. If you are not logged in as root, type the command su - and enter the root password. Type useradd followed by a space and the username for the new account you are creating at the command line (for example, useradd jsmith).
Use useradd
, it doesn't ask any questions but accepts many command line options.
On Ubuntu, you could use the python-libuser package
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With