LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
LinkBack Search this Thread
Old 11-26-2007, 09: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, 02:23 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,008
Blog Entries: 2

Rep: Reputation: Disabled
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.
 
Old 11-27-2007, 05:38 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu (x86), Debian (PPC)
Posts: 3,528

Rep: Reputation: 56
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?
 
  


Reply

Tags
makepasswd, password


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
adduser adding an administrator Cyberman Linux - General 4 09-03-2007 11:43 AM
Automate adding users and passwords linuxy2 Linux - Security 1 03-03-2007 02:32 AM
adding users and passwords to mysql caged Programming 1 10-27-2004 06:22 PM
"adduser" not adding users to default group "users" PunkPT Slackware 2 09-23-2004 12:50 PM
PHP Adding Passwords to connection line Chijtska Programming 2 03-18-2002 10:38 PM


All times are GMT -5. The time now is 09:04 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
Open Source Consulting | Domain Registration