Sponsored Content
Full Discussion: Useradd issue
Operating Systems Linux Red Hat Useradd issue Post 302410405 by m1xram on Tuesday 6th of April 2010 01:24:17 AM
Old 04-06-2010
Perl crypt()

See perldoc -f crypt.
Quote:
crypt PLAINTEXT, SALT
Where PLAINTEXT is the password in this case
Where SALT is a two character string, matches regexp /[./0-9A-Za-z]{2}/
Many people use seconds to come up with a SALT string but in a tight loop you may pull the the same second. Do something with this...
Code:
sub fractime () {
  use Time::HiRes qw ( time );
  my $now = time;
  $now -= int($now);
  return $now;
}

That will give you a factional time where you can use string operators to suck out two digits at a time and the modulo them to the set of 64 characters available for the SALT with...
Code:
sub randsalt($) {
  my ($fractime) = @_;

  my $saltset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
  my $salt = "";
  for (my $i = 0; $i < 2; ++$i) {
    my $s = substr($fractime, ($i * 2) + 2, 2) % length($saltset);
    $salt .= substr($saltset, $s, 1);
  }
  return $salt;
}

So we call these two functions in Perl and return the password.
Code:
my $ft = fractime();
#print $ft, "\n";
my $salt = randsalt($ft);
#print $salt, "\n";
print crypt($ARGV[0], $salt), "\n";

See attachment for Perl code and remember to 'chmod' it. We can now get the proper password in BASH with...
Code:
#!/bin/bash
PASS=$(./test8.pl somepassword)

I tested the 'useradd' command and it worked correctly with adding the account under Fedora12. Sorry for the hedge bet but the documentation says the default '-p' option is to disable the account? This sounds strange.

Good Luck.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

useradd

I work on some hp ux 11.00 Servers. i have to add an user. i use the useradd command like follows: useradd -u 72022 -g 71095 -c " comment " -d /PACKAGE_NAME/home/username -s /usr/bin/sh username The command returns with error 3. The manpage means value number 3: Invalid argument supplied to an... (6 Replies)
Discussion started by: ortsvorsteher
6 Replies

2. UNIX for Advanced & Expert Users

useradd

Hi. due to some needs i gave a user the premission to use useradd command with sudo. i want to know if there is a way to let him set the initial password, without giving him the premission to use passwd command as root (sudo). maybe a way to set a default password for all the new users that... (2 Replies)
Discussion started by: dorilevy
2 Replies

3. Solaris

useradd

Hi, I need to add a new user who will only be able to access one single folder on my Solaris 9 system. Can this be achieved by using just useradd or do i need to fiddle with auth_attr table? TIA, Selma (4 Replies)
Discussion started by: Selma
4 Replies

4. UNIX for Dummies Questions & Answers

useradd question

The man pages for useradd show the -k flag as a option, problem is I don't know what the description means. Could someone explain what "an alternative skel directory" is? Is skel an acronym? Thanks From the man page: -k, --skel skeldir Specify an alternative skel... (1 Reply)
Discussion started by: thumper
1 Replies

5. Shell Programming and Scripting

useradd

Gurus, I need to add a user to all the machines. I need a script to do this. I did one but it does not allow me to su to root within a ssh session i open. It exists saying su: Sorry. Please let me know how i can do it. I do not have the freedom of using sudo either. Regards (4 Replies)
Discussion started by: earlysame55
4 Replies

6. UNIX for Advanced & Expert Users

useradd?

Hi Experts, when using useradd command, what are the necessary options/arguments to be included? Please advice. (4 Replies)
Discussion started by: etcpasswd
4 Replies

7. Shell Programming and Scripting

Help with useradd script

Ok Im trying too make this shell script create users from my text file, I also want to type in a password for the new users. So thay can make a uniq one themself after first logon. #!/bin/sh # Sebastian schmidt clear echo "*************************************************************"... (3 Replies)
Discussion started by: chipmunken
3 Replies

8. Solaris

useradd

if useradd command is deleted in solaris how do we add user (3 Replies)
Discussion started by: vivek_ng
3 Replies

9. Solaris

useradd problem

:wall:i want to create a user in solaris whose password expires after every 30 minutes and he has to change his password after evry thirty minutes.How can we do that?:confused: thanx and regards, shekhar (17 Replies)
Discussion started by: shekhar_4_u
17 Replies

10. Solaris

useradd

I want to creat a 27 logins in solaris.Can anyone tell me how to write a script for that so that i create at a time for all 27 people. Thanks to guide me. (6 Replies)
Discussion started by: kkalyan
6 Replies
md5crypt(n)						   MD5-based password encryption					       md5crypt(n)

__________________________________________________________________________________________________________________________________________________

NAME
md5crypt - MD5-based password encryption SYNOPSIS
package require Tcl 8.2 package require md5 2.0 package require md5crypt ?1.1.0? ::md5crypt::md5crypt password salt ::md5crypt::aprcrypt password salt ::md5crypt::salt ?length? _________________________________________________________________ DESCRIPTION
This package provides an implementation of the MD5-crypt password encryption algorithm as pioneered by FreeBSD and currently in use as a replacement for the unix crypt(3) function in many modern systems. An implementation of the closely related Apache MD5-crypt is also avail- able. The output of these commands are compatible with the BSD and OpenSSL implementation of md5crypt and the Apache 2 htpasswd program. COMMANDS
::md5crypt::md5crypt password salt Generate a BSD compatible md5-encoded password hash from the plaintext password and a random salt (see SALT). ::md5crypt::aprcrypt password salt Generate an Apache compatible md5-encoded password hash from the plaintext password and a random salt (see SALT). ::md5crypt::salt ?length? Generate a random salt string suitable for use with the md5crypt and aprcrypt commands. SALT
The salt passed to either of the encryption schemes implemented here is checked to see if it begins with the encryption scheme magic string (either "$1$" for MD5-crypt or "$apr1$" for Apache crypt). If so, this is removed. The remaining characters up to the next $ and up to a maximum of 8 characters are then used as the salt. The salt text should probably be restricted the set of ASCII alphanumeric characters plus "./" (dot and forward-slash) - this is to preserve maximum compatability with the unix password file format. If a password is being generated rather than checked from a password file then the salt command may be used to generate a random salt. EXAMPLES
% md5crypt::md5crypt password 01234567 $1$01234567$b5lh2mHyD2PdJjFfALlEz1 % md5crypt::aprcrypt password 01234567 $apr1$01234567$IXBaQywhAhc0d75ZbaSDp/ % md5crypt::md5crypt password [md5crypt::salt] $1$dFmvyRmO$T.V3OmzqeEf3hqJp2WFcb. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category md5crypt of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. SEE ALSO
md5 KEYWORDS
hashing, md5, md5crypt, message-digest, security CATEGORY
Hashes, checksums, and encryption COPYRIGHT
Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net> md5crypt 1.1.0 md5crypt(n)
All times are GMT -4. The time now is 02:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy