Frage

I try to write c program program to add user in Linux this is my code

char a[50];
char command[150];
printf("Please enter username \n");
fgets(a,sizeof(a),stdin);
strcpy(command,"useradd ");
strcat(command,a);
system(command);

but this code can't run correctly when i use it the shell show the man command help for useradd
how i use this command correctly to add user using c ?

War es hilfreich?

Lösung

but a is the name of user? you need to assign in what group the user will be add:

useradd -G groupname username

try:

strcpy(command,"useradd -G <groupname>");
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top