Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic script for making new users

Status
Not open for further replies.

trygvex

Technical User
Jul 23, 2003
1
NO
We are using AIX 4.3.3 and 5.1/5.2.

I need a script that:

1. Makes a new user
2. Sets the password to the same as username

The problem with mkuser is that it doesn't make the password. How can i do this?

Greetings from Norway
 
I don't think you can do this unless you use a 3rd party tool like 'expect'.

Alex
 
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:

script:

#!/usr/bin/csh
mkuser pgrp='PrimGroup' groups='GroupSets' home='HomeDir' shell='/bin/csh' gecos=&quot;$2&quot; umask='002' $1
passwd $1

run process:

# ./adduser joe &quot;Joe Smith&quot; <enter>
Changing password for &quot;joe&quot;
joe's New password:
Enter the new password again:

adduser = script
joe = new user ID
&quot;Joe Smith&quot; = User Information

Hope this helps
Scottweb

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top