Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a user in linux using python

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?

like image 838
Salsa Avatar asked Jul 06 '10 23:07

Salsa


People also ask

Which command is used to create user in Linux?

useradd is a command in Linux that is used to add user accounts to your system.

How do I create a new user in Unix?

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).


2 Answers

Use useradd, it doesn't ask any questions but accepts many command line options.

like image 126
Pavel Strakhov Avatar answered Sep 27 '22 17:09

Pavel Strakhov


On Ubuntu, you could use the python-libuser package

like image 43
unutbu Avatar answered Sep 27 '22 19:09

unutbu