Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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

Try something like this, sudo -- useradd

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top