How to create a linux user using C/C++?

后端 未结 3 1145
半阙折子戏
半阙折子戏 2020-12-10 16:20

I would like to build a program which takes a username as parameter and creates the user and its home folder (with some hard-coded specifications like folde

相关标签:
3条回答
  • 2020-12-10 16:31

    Probably your best bet is to invoke useradd; it will do the right things (given appropriate parameters).

    Trying to create one manually by calling the appropriate APIs is possible but not desirable.

    0 讨论(0)
  • 2020-12-10 16:50

    You mean like adduser or useradd? Try looking at their source code.

    0 讨论(0)
  • 2020-12-10 16:50

    There is no API for this. You just write into /etc/passwd and /etc/group (and possibly the shadow versions as well) using normal file access system calls.

    0 讨论(0)
提交回复
热议问题