File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes how to assign password for a user in shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to assign password for a user in shell script" Watch "how to assign password for a user in shell script" New topic
Author

how to assign password for a user in shell script

pavan bellari
Greenhorn

Joined: Sep 19, 2003
Posts: 24
The problem is to create a new user and assign a password for that user from the shell script instead of at prompt.
i have create a file using vi editor
and i have typed
useradd xyz
passwd xyz pqr
and when i run the shell by giving bash file name, the new user is created but the password is not assigned. it is treating pqr is also a username
please tell me how to assign password for a user from the shell script
[ October 16, 2003: Message edited by: pavan bellari ]
Richard Klein
Greenhorn

Joined: Oct 16, 2003
Posts: 4
Hi
You can generate a password with the useradd command :
useradd [-c comment] [-d home_dir]
[-e expire_date] [-f inactive_time]
[-g initial_group] [-G group[,...]]
[-m [-k skeleton_dir] | -M] [-p passwd]
[-s shell] [-u uid [ -o]] [-n] [-r] login
Richard
pavan bellari
Greenhorn

Joined: Sep 19, 2003
Posts: 24
hello Mr Richard Klein
Thanks for ur quick reply.
I had already tried what u said useradd -p option. no error is shown in that
but when we login with the user created with useradd -p it is not allowing to login.
but when we entered as root and tried to create useradd with the username above it is showing that user already exists
that means though we give the command useradd -p it is creating the new user but not assigning the password
pls reply this soon
thanks in advance
Richard Klein
Greenhorn

Joined: Oct 16, 2003
Posts: 4
You could try the following:
useradd $account_name
echo $account_pwd | passwd --stdin $account_name
Regards
Richard
pavan bellari
Greenhorn

Joined: Sep 19, 2003
Posts: 24
Thanks Mr Richard Klien
It is working well.
U have done a great job to me. It is very much worth for me. I am in the mid of project . If any doubts can i contact u. pls give me ur mail id
Thank u very much
one more doubt. If possible pls clarify
I am connecting Windows and Linux machine thru Java RMI. and my server files are in Linux Server. when I connect Linux machine(144.16.75.124) thru Java on Windows It is showing error:
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: no further information
although I have given the ip-address of the linux machine(here it is 144.16.75.124). The error is Connection refused to host: 127.0.0.1
and I haven't mentioned 127.0.0.1 or localhost any where in the program
 
Consider Paul's rocket mass heater.
 
subject: how to assign password for a user in shell script
 
Similar Threads
log-in as ROOT with ANT
Writing input data to a properties file
Retrieve delimetted value from String
split function problem in AWK
Load Text file and display in table format.