Pages

Monday, September 12, 2016

Create Linux users using a C program

Today, in order to further familiarize myself with C programming, I wrote a program to automate the process of creating new users. This program is for personal use only, meaning if you are running this on a server with many users, you run the risk of something being passed to the program that can harm your system.

Here's the source code:


#include <stdio.h>
#include <stdlib.h>

//Created by Brian Winkler
//Create new user

int main (void) {
        char user[128];
        char add[128];
        
        
        printf("Enter a user name:\n");
        scanf("%s", user);
        
        snprintf(add, sizeof(add), "useradd -m -G users -s /bin/bash %s", user);
        system(add);

        printf("User %s created!\n", user);
        return 0;
    
    
}

It's a very simple program but through compounding Linux commands, a very powerful program can be created. This program has been tested on Arch Linux and Ubuntu 14.04.

This source code can also be found on my github.



No comments:

Post a Comment