?
Solved

useradd

Posted on 2002-06-27
6
Medium Priority
?
712 Views
Last Modified: 2013-12-27
hi all,
Is there a way to define a group, user and password
in a script in a NON-interactive way ?
if there is I will be happy to get an example.
thanks,
Eran
0
Comment
Question by:raichel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7113048
what exactly do you mean by  "define a group, user ..."?

If you mean to create new users in /etc/passwd with passwords programatically, you need to program it in Tcl's expect for example.
Do you have expect?
0
 

Author Comment

by:raichel
ID: 7113093
My question is very simple :-)
I want to use useradd in order to create new user on    unix.
no problems until now.
I want to use passwd in order to give the password.
Here comes the problem :
passwd is an interactive command which will stop my script
and force the person which runs it to be involved
I dont want him to be involved do you know a way to define the password in a noninteractive way
thanks and sorry for not being clear.
Eran
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7113102
> .. do you know a way to define the password in a noninteractive way ..
expect http://expect.nist.gov/
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 38

Expert Comment

by:yuzh
ID: 7115472
You can simply write a script to do the follwings to add a
user:

1. create a dummy user use admintool or useradd. (you just
   need the passord from the /etc/shadow file, cut and  
   paste the password field and save to a file for later
   use. you can cahnge the password for dummy user and
   store the password in a file. (once you get enough  
   passords, you can delete the dummy user from your  
   system)

2. use useradd to add a new user (this will not promt you
   for the password)
   
useradd -c "User comment or GCOS" -d /home/newuser -g group -m -k /etc/skel -s /bin/sh newuser

3. use awk/sed to replace the passord field with the
  password you want from the dummy password file.

   or
 do as ahoffmann told you. write an expect script to handle
the passwd in noninteractive way.




0
 

Accepted Solution

by:
wfang01 earned 200 total points
ID: 7155748
For example, to create a user John Wayne with login id jwayne, uid 7000, gid 100, do this:

#printf "jwayne:x:7000:100:John Wayne:/users/jwayne:/bin/ksh\n" >> /etc/passwd

#printf "jwayne::11000::::::\n" >> /etc/shadow

Note:
1. In this example, the password field is empty to allow the user to input his own at the first time he logs on. You can change it to anything else you like, such as "password"(you can cut and paste the encrypted characters of a common password by creating it manually first using tools like passwd or admintools).
2. "11000" here is just a random number.
3. chmod needs to be done before you can edit the passwd and shadow file.
0
 
LVL 2

Expert Comment

by:blowfish
ID: 7218971
Althought the answer proposed by wfang01 is likley to work, it is should not be attempted, nor ever recommended.  There is too much of a chance of corrupting the files, and possibly getting into a situation where you can no longer login to your system.  What of file locking?  What prevents corruption of the file when more than one process is using it?  What happens if a Solaris utility like passwd, or useradd, or userdel is run at the same time.  Not to mention what happens while you're on vacation and someone has problems adding a user, so they need to modify your script ... there's a lot of slashes and colons there, an unfortunate typo will generate some interesting side effects.  Don't vi the file, and don't use awk or sed either.  

BTW, 11000 is not a random number so don't go putting random numbers in there.  That field is the number of days since January 1, 1970 when the password was last changed.  The value 11000 works out to Sat Feb 11, 2000.  Okay, so 11000 is a good value, just don't put a random number in there.  

So what to use for (scripted) automation of the passwd command?  Expect is really the best and only alternative.  

There just happens to be an article in July 2002 SysAdmin on using Expect.  One of the things discussed is using Expect for password changes.  

Regards,

--frankf
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question