Question

I want to create C application to add user in Linux with useradd command .

I write this code when i use it terminal print error message:

useradd :permission denied
useradd :cannot lock/etc/passwd; try again later 

this is my C code to add user such as i want to add user1 just write user1

char a[50];
char command[150];
fgets(a,sizeof(a),stdin);
strcpy(command,"useradd ");
strcat(command,a);

how i can solve this problem with correct syntax or command?

Était-ce utile?

La solution

if sudo package is not installed, You can install it. Or you can create it as a root using su . It will ask root password after that you can use any superuser caommnads.

Autres conseils

This is because you need to run the command with root privileges.

Try something like this, sudo -- useradd

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top