HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need to create a script for user creation and pass...
Operating System - HP-UX
1827464
Members
4550
Online
109965
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2010 01:50 AM
12-14-2010 01:50 AM
Need to create a script for user creation and passwd
Hi,
Can anyone pls let me know how to create a script which will create a user and given passwd also through script?
Like i want to create a user "test" and i also want the passwd for this user is "test" through script.
Appreciaitng your help
Regards,
Shikhar Verma
Can anyone pls let me know how to create a script which will create a user and given passwd also through script?
Like i want to create a user "test" and i also want the passwd for this user is "test" through script.
Appreciaitng your help
Regards,
Shikhar Verma
- Tags:
- passwd
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2010 04:37 AM
12-14-2010 04:37 AM
Re: Need to create a script for user creation and passwd
The creation of the account is easily scriptable because you only need to call the useradd (and if required the groupadd) command.
See their manpage for details about options and arguments.
The tricky part might be the scripted setting of a password because the passwd command can only be executed in interactive mode.
However, some care for proper file format and advisory file locking provided you can edit /etc/passwd (or /etc/shadow if you run a "passwd shadowed" system) throug a script as well. You only need to find some function that would generate the encrypted hash string.
I should think that most "dynamic languages" provide such hash functions.
Personally, I would make a Perl call to the crypt() function (standard Perl, see "perldoc -f crypt") if you have to deal with old-style Unix passwd encryption, or a CPAN module like Crypt::PasswdMd5 (http://search.cpan.org/~luismunoz/Crypt-PasswdMD5-1.3/PasswdMD5.pm) if you have to deal with MD5 encrypted passwords.
See their manpage for details about options and arguments.
The tricky part might be the scripted setting of a password because the passwd command can only be executed in interactive mode.
However, some care for proper file format and advisory file locking provided you can edit /etc/passwd (or /etc/shadow if you run a "passwd shadowed" system) throug a script as well. You only need to find some function that would generate the encrypted hash string.
I should think that most "dynamic languages" provide such hash functions.
Personally, I would make a Perl call to the crypt() function (standard Perl, see "perldoc -f crypt") if you have to deal with old-style Unix passwd encryption, or a CPAN module like Crypt::PasswdMd5 (http://search.cpan.org/~luismunoz/Crypt-PasswdMD5-1.3/PasswdMD5.pm) if you have to deal with MD5 encrypted passwords.
Madness, thy name is system administration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2010 03:54 PM
12-14-2010 03:54 PM
Re: Need to create a script for user creation and passwd
Hello,
Many ways to do it.
One is in my Perl script:
http://www.circlingcycle.com.au/Unix-sources/add-batch-Unix-accounts.pl.txt
Cheers,
Dusan
Many ways to do it.
One is in my Perl script:
http://www.circlingcycle.com.au/Unix-sources/add-batch-Unix-accounts.pl.txt
Cheers,
Dusan
VK2COT - Dusan Baljevic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2010 07:54 PM
12-14-2010 07:54 PM
Re: Need to create a script for user creation and passwd
Personally I would use the command useradd.sam, this allows you to specify the password when you add the user.
So a simple script that creates a user (and sets the password) with the supplied parameter would be
#!/usr/bin/ksh
if [ ! -z "$1" ]
then
PASSWORD=$1
while [ $(echo $PASSWORD | wc -c) -lt 9 ]
do
PASSWORD=$PASSWORD"\0"
done
/usr/sam/lbin/useradd.sam -p $(echo ${PASSWORD}xx|/usr/lbin/makekey) $1
else
echo "Syntax: $0"
fi
This can then be expanded on to add error checking and any other additional options that are required such as defining the uid, group etc etc
So a simple script that creates a user (and sets the password) with the supplied parameter would be
#!/usr/bin/ksh
if [ ! -z "$1" ]
then
PASSWORD=$1
while [ $(echo $PASSWORD | wc -c) -lt 9 ]
do
PASSWORD=$PASSWORD"\0"
done
/usr/sam/lbin/useradd.sam -p $(echo ${PASSWORD}xx|/usr/lbin/makekey) $1
else
echo "Syntax: $0
fi
This can then be expanded on to add error checking and any other additional options that are required such as defining the uid, group etc etc
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP