Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sorry, I realised my mistake whilst you were composing your reply.
No problem.
Quote:
Originally Posted by Disillusionist
You could use usermod -p $ENCPW $UN so long as you have a valid encrypted password but you're going to need to create that encrypted password somewhere.
Yeah, and this is where I'm at: Where can I create an encryptet password without having to create/modify an existing user? I essence, what I'd like is access to the same encryption function that "passwd" uses.
Yeah, and this is where I'm at: Where can I create an encryptet password without having to create/modify an existing user? I essence, what I'd like is access to the same encryption function that "passwd" uses.
passwd uses crypt but with a random salt begining $1$
For example, create a user testuser2 with the password Testing
Then tail /etc/shadow
On my system I get:
#!/usr/bin/perl
use strict;
my $SALT='$1$5ObqRtny';
my $pass="Testing";
my $ENC=crypt($pass, $SALT);
print("Password : $pass\n");
print("Encrypted: $ENC\n");
OK, I think I've finally finished tweaking the code!
/usr/local/bin/new_user.pl
Code:
#!/usr/bin/perl
use strict;
use String::Random qw(random_string);
## String::Random can be found: http://search.cpan.org/~steve/String-Random-0.20/Random.pm
my ($USER, $pass)=@ARGV;
my $SALT=random_string("ssssssssss");
my $PASS_SALT=("\$1\$$SALT");
my $ENC=crypt($pass, $PASS_SALT);
system("useradd -p '$ENC' -m $USER");
/usr/local/bin/bulk_useradd.pl
Code:
#!/usr/bin/perl
use strict;
my ($list)=@ARGV;
my $line;
open(LIST, $list) or die "Couldn't open $list\n";
my @userlist=<LIST>;
close(LIST);
foreach $line (@userlist) {
my ($USER,$PASS)=split(',',$line);
system("perl /usr/local/bin/new_user.pl $USER $PASS");
}
But AFAIK the "passwd" modifies an existing user. I don't want to modify or create a user at all, just create an encrypted password. Am I missing something here?
#!/usr/bin/perl
##
## Script: encrypt.pl
use strict;
use String::Random qw(random_string);
## String::Random can be found: http://search.cpan.org/~steve/String-Random-0.20/Random.pm
my ($pass)=@ARGV;
my $SALT=("\$1\$" . random_string("ssssssss") );
##
## If you cant get String::Random then just use your own SALT eg:
## my $SALT=("\$1\$GSx8s72d");
my $ENC=crypt($pass, $SALT);
print("Encrypted Pass: $ENC\n");
This expects the unencyrpted password to be passed as an argument:
#!/usr/bin/perl
##
## Script: encrypt.pl
use strict;
use String::Random qw(random_string);
## String::Random can be found: http://search.cpan.org/~steve/String-Random-0.20/Random.pm
my ($pass)=@ARGV;
my $SALT=("\$1\$" . random_string("ssssssss") );
##
## If you cant get String::Random then just use your own SALT eg:
## my $SALT=("\$1\$GSx8s72d");
my $ENC=crypt($pass, $SALT);
print("Encrypted Pass: $ENC\n");
This expects the unencyrpted password to be passed as an argument:
encrypt.pl Password
Thanks, but this is perl. I'd like a (bash) shell equivalent of this if possible. I mentioned this a few posts back, but I'm sure it's not easy to keep track of what everyone has written.
Anyways: If there is a (bash) shell equivalent for this, in which I can create an encrypted password that _may_ be added to /etc/shadow later on, please let me know. The reason for doing it this way is that for some users I define them in our administration program (Puppet), and distribute the encrypted password to the the servers in our network. So the encrypted password are added to a text file and distributed to the /etc/shadow file of our servers.
Very useless script its not working properly it damage my system passwd file please do not try at home
error
what do you mean by mkpasswd
As written the script doesn't touch your passwd or shadow files, it does nothing but echo information to the screen (should be in the format of "useradd -p yXI6rY4uwosLQ username"). If you remove the echo it will simply run the useradd command with whatever command line was echoed to the screen in the dry run.
Even if fed incorrect information (badly formatted csv) it can only pass that bad information to the useradd program which shouldn't do any damage to your passwd or shadow files. The useradd program has no destructive flags, so even if you try to make a user named various random flags instead of a name it would just make a non-usable user.
Based on the information at the bottom of your post it looks like your system doesn't have mkpasswd installed by default or it's not in your path. Which means, largely, that you would get the unencrypted password added to the password file, which still wouldn't allow login.
Last edited by rweaver; 01-05-2009 at 08:24 AM.
Reason: extra information at bottom of post
Thanks, but this is perl. I'd like a (bash) shell equivalent of this if possible. I mentioned this a few posts back, but I'm sure it's not easy to keep track of what everyone has written.
Anyways: If there is a (bash) shell equivalent for this, in which I can create an encrypted password that _may_ be added to /etc/shadow later on, please let me know. The reason for doing it this way is that for some users I define them in our administration program (Puppet), and distribute the encrypted password to the the servers in our network. So the encrypted password are added to a text file and distributed to the /etc/shadow file of our servers.
To the best of my knowledge (and numerous Google searches) there is no way to do this directly from bash.
mkpasswd uses crypt, however it only allows 2 character SALT's and therefore will not give the type of password that you are after.
I must admit that I don't see an issue with calling a perl script from bash (unless you don't have perl installed).
[QUOTE=Disillusionist;3398100]To the best of my knowledge (and numerous Google searches) there is no way to do this directly from bash.
QUOTE]
Thanks, that's all I needed to know. I was hoping there would be some way of doing this directly from bash, but going for the perl method is not a problem.
Dear Guys,
After my tour I just sit with my office and gone through this thread and lot of informations and knowledgeI I gained. And my heartly thanks for all shared their knowledge here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.