在 Unix 中添加用户和组
问题描述:
有谁知道在unix中添加用户和组并删除它们的api?我想以编程方式执行此操作.
Does anyone know the api for adding users and groups in unix and removing them ? I want to do this programatically.
谢谢,弗兰克
答
我在寻找一种在 Unix 上列出所有组的方法时发现了这个问题.但是要创建和删除用户,您可以以编程方式调用实用程序 useradd、userdel、groupadd、groupdel,因为您会知道发送的用户名.但我想你需要超级用户权限才能调用它们.无论如何,您可以检查进程退出代码的命令状态.
I found this question while looking for a way to list all groups on a Unix. But to create and delete users you can programatically call the utility programs useradd, userdel, groupadd, groupdel since you would know the user name been sent. But I guess you will need superuser rights to invoke them. Anyway you can check the process exit code for command status.
useradd xxx // status zero operation completed
useradd xxx // status nine user already exists
希望有帮助.