Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I need to created some users in linux machine through RPM.
I am able to create users but unable to set passwd. Any ways to do it?
I am trying to build such RPM by calling a shell script in the %post section of spec file. But when I install this RPM passwd prompt doesn't stay for user input, it is skipped.
I realize this is a very old thread but it remains unanswered and there are those out there who might still require an answer to this question.
My solution to this was first to create a quick shell script to encrypt a password with MD5 encryption. Then in the %pre section, I added the following.
%pre
if [ `grep -c ^user /etc/passwd` = "0" ]; then
/usr/sbin/useradd -c 'User Comment' -d /path/to/user/home -p 'encrypted password' -s /bin/bash user
fi
And here is a quick script to create encrypted passwords
#!/usr/bin/perl -w
use Term::ReadKey;
# Enable(1) / Disable(0) debug output
$debug = 1;
# Enable(1) / Disable(0) verbose to display passords before encryption on a failed comparison
$verbose = 1;
# Check for command line argument to set the type of salt to use. Default is DES.
$salttype = shift;
if ( $salttype && $salttype =~ /-md5/ ) {
# Generate a random salt using MD5
$salt = '$1$';
$salt .= `cat /dev/urandom | tr -dc '0-9a-zA-Z' | head -c 8`;
} elsif ( $salttype ) {
print "\nUnrecognized option: $salttype, Exiting!\n\n";
print "USAGE: encpass [-md5]\n\n";
exit;
} else {
# Generate a random salt using DES
$salt = `cat /dev/urandom | tr -dc '0-9a-zA-Z' | head -c 2`;
}
if ($debug) { print "DEBUG-salt:\'$salt\':\n"; }
# Prompt for a password
print "\n\tEnter a NEW password to encrypt: ";
ReadMode('noecho');
$default_password = ReadLine(0);
chomp $default_password;
# Prompt for same password a second time to avoid typos
print "\n\tConfirm NEW password: ";
$confirm_password = ReadLine(0);
chomp $confirm_password;
ReadMode(0);
print "\n";
# Compare the two passwords and exit if they don't match
unless ($default_password =~ /^\Q$confirm_password\E$/) {
if ($debug) { print "pass1:$default_password:\npass2:$confirm_password:\n"; }
die "\nPasswords entered do NOT match!\n\n";
}
# Print out the encrypted password
print "\nYour password encrypted as: ";
print crypt($confirm_password, $salt);
print "\n\n";
Nice script but prompting for user input is not how RPM works or how it should work.
I think you need to read my first post a little closer. I specifically said I wrote a script to generate passwords and then used said encrypted passwords with the useradd command in the pre install script of my RPMs.
Nah, the rpm's I am generating are for my company's own software. Our software needs a user to run as to avoid the whole running as root security hole.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.