Re: script to create new user and set a password (932 Views)
Reply
Regular Advisor
itrc55
Posts: 195
Registered: ‎04-10-2010
Message 1 of 7 (982 Views)

script to create new user and set a password

[ Edited ]

Hi,

 

i have more than 150 servers, please i need a script to create new user and set a password, where i can't login to each server to set password. i have a tools to push and run this script on all servers. but only i need this script.

 

And all system on trusted mode  and OS is HP-UX 11.31.

 

i don't need interactive script because i want to push it to all user to create specific user with specific password

 

your support please.

 

 

Thanks

Honored Contributor
VK2COT
Posts: 921
Registered: ‎01-17-2006
Message 2 of 7 (969 Views)

Re: script to create new user and set a password

Hello,

 

Maybe this can hep you:

 

http://www.circlingcycle.com.au/Unix-sources/add-batch-Unix-accounts.pl.txt

 

You will possibly need to modify it a bit to match your exact needs.

 

 

VK2COT - Dusan Baljevic
Regular Advisor
itrc55
Posts: 195
Registered: ‎04-10-2010
Message 3 of 7 (962 Views)

Re: script to create new user and set a password

Hi,

 

thanks for your support, but i need a simple scripts if you have, when i try to modify this script will take more time.

i am not a good to write scripts.

 

thanks agin.

Regular Advisor
itrc55
Posts: 195
Registered: ‎04-10-2010
Message 4 of 7 (936 Views)

Re: script to create new user and set a password

Hi,



please any help, your support.



Thanks
Honored Contributor
Matti_Kurkela
Posts: 6,271
Registered: ‎12-02-2001
Message 5 of 7 (932 Views)

Re: script to create new user and set a password

Actually, you don't need a script. You just need to run one command in each host to create the user. But first you'll need to generate an encrypted (actually hashed) password for the new user.

 

An encrypted password can be created using the "openssl passwd" command:

$ openssl passwd -crypt
Password: <type the password here> 
Verifying - Password: <type the password again here>
<encrypted_password_here>

If you run this command again and type the same password, you will get a different encrypted password string each time. This is normal.

 

 

Once you have the password in encrypted form, you can build the command for creating the user account.

The command to create an account "jluser" for John L. User would be:

/usr/sbin/useradd -c 'John L. User' -m -p '<encrypted_password_here>' jluser

Run "man useradd" and read to find out what the options mean.

 

NOTE: since the encrypted password may contain characters that have a special meaning to the shell, you should use single quotes around it, exactly as in the example above. The single quotes are the "strongest" quotes available in any common Unix shell.

 

NOTE 2: the encrypted password generated by "openssl passwd -crypt" is a bit weak: with modern computers, it is too easy to check a large dictionary of words and find the original password that matches a given encrypted password. But it is the only form of encrypted password that is acceptable for all HP-UX 11.31 password configurations: traditional Unix mode, the deprecated Trusted System Mode, and the Shadow Password mode.

 

NOTE 3: read the documentation of your command-pushing tool and see if it treats any characters specially. If it does, and your encrypted password string contains one of the special characters, you may need to do something to tell the command-pushing tool to not apply the special meaning of the character in the encrypted password. If your command-pushing tool is any good, it should be able to do this.

MK
Regular Advisor
itrc55
Posts: 195
Registered: ‎04-10-2010
Message 6 of 7 (925 Views)

Re: script to create new user and set a password

Hi,

thanks for your support, i run the below commands on each servers.

$ openssl passwd -crypt
Password: <type the password here>
Verifying - Password: <type the password again here>
<encrypted_password_here>

/usr/sbin/useradd -m -p '<encrypted_password_here>' newuser

/user/lbin/modprpw -v newuser ====> to reset aging password to zero

Thanks
Advisor
Sachin Rajput
Posts: 22
Registered: ‎10-26-2007
Message 7 of 7 (898 Views)

Re: script to create new user and set a password

So are you happy with the above solution ..

I think if you put that in a loop to run on all the servers . you will need to give password for each server two times .

If you want to avoid entering the passwd everytime instead specify command line . YOu can use expect ..

If need any help related to expect let me know .

Sachin Rajput
=============


Sachin Rajput
================
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.