To do this requires a combination of script and a C program to generate the salted crypted password.
Creating the new user is no problem, it is the password setting and changes. It is possible to modify the /etc/security/passwd file directly once you create a crypted password with a salt. Then make sure you run pwdck and mkpasswd to build the db files for efficiency.
#include <stdio.h>
#include <pwd.h>
int
main(int argc, char **argv)
{
int i, c;
long salt;
char saltstr [4];
char pass [20];
char *cpass;
salt = time(&salt);
salt += getpid();
saltstr [0] = salt & 077;
saltstr [1] = (salt>>6) & 077;
for(i=0;i<2;i++)
{
c = saltstr + '.';
if(c>'9') c += 7;
if(c>'Z') c += 6;
saltstr = c;
}
strcpy(pass,argv [1]);
cpass = crypt(pass,saltstr);
puts(cpass);
exit(0);
}
This gives you an encrypted password that can be added directly to the file. (Make sure that your script copies the old password file before modifying it so if it bombs you can recover by copying it back.
This is a script we run as root user on our system when we add a new user. When you run this script you will need to add a password and then when the user logs in for the first time he will need to create a new password. The script called adduser is run from command line:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.