LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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

Reply
 
LinkBack Search this Thread
Old 10-10-2005, 08:53 AM   #1
techie_techie
LQ Newbie
 
Registered: Oct 2005
Posts: 3

Rep: Reputation: 0
How to create users from a RPM package


Hi,

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.

Any help greatly appreciated.

TIA,
Sachin
 
Old 11-11-2011, 02:24 AM   #2
OS Jockey
LQ Newbie
 
Registered: Apr 2008
Location: San Jose, CA.
Distribution: CentOS
Posts: 10

Rep: Reputation: 1
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
 
Old 11-11-2011, 02:35 AM   #3
OS Jockey
LQ Newbie
 
Registered: Apr 2008
Location: San Jose, CA.
Distribution: CentOS
Posts: 10

Rep: Reputation: 1
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";
 
Old 11-11-2011, 03:33 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,610
Blog Entries: 47

Rep: Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413
Quote:
Originally Posted by OS Jockey View Post
[code]# Prompt for a password
print "\n\tEnter a NEW password to encrypt: ";[code]
Nice script but prompting for user input is not how RPM works or how it should work.
 
Old 11-12-2011, 02:00 AM   #5
OS Jockey
LQ Newbie
 
Registered: Apr 2008
Location: San Jose, CA.
Distribution: CentOS
Posts: 10

Rep: Reputation: 1
Quote:
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.
 
Old 11-12-2011, 05:11 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,610
Blog Entries: 47

Rep: Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413
Quote:
Originally Posted by OS Jockey View Post
I think you need to read my first post a little closer. I specifically said I wrote a script to generate passwords
Sorry, missed that.


Quote:
Originally Posted by OS Jockey View Post
and then used said encrypted passwords with the useradd command in the pre install script of my RPMs.
Somehow I get the feeling this is a bad idea. Luckily you aren't distributing those packages, right?
 
Old 11-12-2011, 10:49 AM   #7
OS Jockey
LQ Newbie
 
Registered: Apr 2008
Location: San Jose, CA.
Distribution: CentOS
Posts: 10

Rep: Reputation: 1
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create a standard package linetnew Programming 1 10-15-2005 02:52 PM
create RPM-package from installed files ? hungnt Linux - Software 1 07-10-2005 11:17 PM
how to create .rpm package shalin Programming 1 07-13-2004 10:12 AM
how to create RPM Package shalin Programming 0 03-09-2004 11:04 PM
can reinstall the rpm package without delete the rpm package eye Red Hat 1 10-20-2003 07:53 AM


All times are GMT -5. The time now is 05:40 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration