Solved

useradd

Posted on 2002-06-27
6
704 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
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 50 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now