Script to add user and password without using CLI
Hi,
I need to add a user and password from a shell script on several machines.the username and password will remain same for all machines.so i need to put that in the script. but it prompts me for passwrd on CLI. i dont want that to happen.i want it to pick from the script itslef. for example, username:lalita password:lalita is it possible? please help! |
The useradd binary (which I can only assume you are using in this shell script) takes the username and password as options, so you just need to do:
Code:
useradd -p password username |
I tried that. but then when i log in as that user it does not prompt me for password.
Quote:
|
|
Quote:
|
I was doing that. so now i logged out and tried to log in.
But it says password incorrect.where am i going wrong? Quote:
|
Perhaps you are using the wrong password? :scratch:
|
i thought so too and cross checked it but did not help.im sorry for being so ignorant but i have no clue how to get it fixed.
Quote:
|
From the useradd man page (man useradd):
Code:
-p, --password PASSWORD |
You can always write a script that adds the appropriate entries to /etc/passwd, /etc/group, /etc/shadow, creates the user's home directory, and changes ownership of said directory. I would suggest you see if the user is already in the password file before proceeding with the other steps.
Code:
grep ^username: /etc/passwd |
The user is not already there in password file.But i am really not sure how to write the script for this task which you have suggested. :confused:
Quote:
|
Actually, I did a little research and I found out you can generate the password hash with the command:
Code:
openssl passwd -1 Code:
useradd -p password 'output from above' username |
All times are GMT -5. The time now is 01:21 PM. |