如何使用python在Linux中创建用户 [英] How to create a user in linux using python

查看:373
本文介绍了如何使用python在Linux中创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux中使用Python创建用户?我的意思是,我了解子流程模块,并考虑过调用"adduser"并立即传递所有参数,但是"adduser"命令会询问一些问题,例如密码,全名,电话和其他东西.如何使用子流程回答这个问题? 我在此问题中看到过名为pexpect的模块:我可以使用Python作为Bash替代品?.还有其他标准模块吗?

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,它不会提出任何问题,但可以接受许多命令行选项.

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

这篇关于如何使用python在Linux中创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆