LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-26-2007, 08:33 PM   #1
sean04
LQ Newbie
 
Registered: Oct 2007
Posts: 8

Rep: Reputation: 0
adding users and passwords with adduser


I'm trying to create a new user with a password via script file and I'm using the -p option for the password but, I need to give it the crypted password as returned by crypt() function. This is what is says in the man pages for adduser.

The problem is in my script the crypt command is not found. Therefore I cannot create a crypted password.

Help please! This is in RHEL 4.
 
Old 11-27-2007, 01:23 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

crypt() is not a function that you can use in bash, it is a c(++) function. If you want to use it you need to write a little c (or c++) script around it. After compiling you'll end up with a binary that can produce the encrypted password needed by useradd's -p option.

This rough example creates md5 encrypted passwords:
Code:
#define _XOPEN_SOURCE
#include <stdio.h>
#include <unistd.h>

int main (int argc, char* argv[])
{
  char *result;

  printf ("%s\n", crypt (argv[1], "$1$"));

  return (0);
}

/*  gcc -lcrypt md5.crypt.c -o md5.crypt  */
Save it as md5.crypt.c . After compiling it with: gcc -lcrypt md5.crypt.c -o md5.crypt, you'll end up with md5.crypt

An example run:
Code:
$ ./md5.crypt FooBar
$1$$yNWeilBBQ6tKlG4nsnV9W.
Hope this helps.
 
1 members found this post helpful.
Old 11-27-2007, 04:38 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
You could use the makepasswd program (you will probably need to install it first):
Code:
echo "mypassword" | makepasswd --clearfrom=- --crypt-md5 |awk '{ print $2 }'
Weird that so many users are suddenly asking this question, or one very like it. Is this some sort of assignment, or are you asking the same question logged in as multiple users?
 
Old 03-12-2012, 03:11 AM   #4
1300
Member
 
Registered: Nov 2011
Posts: 39

Rep: Reputation: Disabled
Post

Quote:
Originally Posted by druuna View Post
Hi,

crypt() is not a function that you can use in bash, it is a c(++) function. If you want to use it you need to write a little c (or c++) script around it. After compiling you'll end up with a binary that can produce the encrypted password needed by useradd's -p option.

This rough example creates md5 encrypted passwords:
Code:
#define _XOPEN_SOURCE
#include <stdio.h>
#include <unistd.h>

int main (int argc, char* argv[])
{
  char *result;

  printf ("%s\n", crypt (argv[1], "$1$"));

  return (0);
}

/*  gcc -lcrypt md5.crypt.c -o md5.crypt  */
Save it as md5.crypt.c . After compiling it with: gcc -lcrypt md5.crypt.c -o md5.crypt, you'll end up with md5.crypt

An example run:
Code:
$ ./md5.crypt FooBar
$1$$yNWeilBBQ6tKlG4nsnV9W.
Hope this helps.
sample:
useradd -g addm -d /home/bbd -m -c "ADDM user" -p '$1$$obKSzVJoc/mJ1ozCv.5/z.' -s /bin/bash bbd
 
  


Reply

Tags
crypt, makepasswd, password, useradd


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
adduser adding an administrator Cyberman Linux - General 4 09-03-2007 10:43 AM
Automate adding users and passwords linuxy2 Linux - Security 1 03-03-2007 01:32 AM
adding users and passwords to mysql caged Programming 1 10-27-2004 05:22 PM
"adduser" not adding users to default group "users" PunkPT Slackware 2 09-23-2004 11:50 AM
PHP Adding Passwords to connection line Chijtska Programming 2 03-18-2002 09:38 PM


All times are GMT -5. The time now is 07:50 AM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration