Hello guys
I have a new Centos 5.3 running, and I have a text file with a bunch of accounts (more than 100) that I should create . File format is like this
user1 pasword1 user2 passwrd2 ....
How can I do this task easier than creating user one by one by hand? Need some help for building an script to achieve this task
Thanks David
David Leon wrote:
Hello guys
I have a new Centos 5.3 running, and I have a text file with a bunch of accounts (more than 100) that I should create
What's the question? How to do it? Parse the text file and use something like useradd to add the accounts, is probably the quickest way.
nate
I'm trying to avoid typing every password manually. I just need an script that makes the job.
useradd creates the account but still need to setup accpunt's password.
On 8/3/09, nate centos@linuxpowered.net wrote:
David Leon wrote:
Hello guys
I have a new Centos 5.3 running, and I have a text file with a bunch of accounts (more than 100) that I should create
What's the question? How to do it? Parse the text file and use something like useradd to add the accounts, is probably the quickest way.
nate
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Use expect/autoexpect + apg tool. Thank you. On 03/08/09 21:49, David Leon wrote:
I'm trying to avoid typing every password manually. I just need an script that makes the job.
useradd creates the account but still need to setup accpunt's password.
On 8/3/09, natecentos@linuxpowered.net wrote:
David Leon wrote:
Hello guys
I have a new Centos 5.3 running, and I have a text file with a bunch of accounts (more than 100) that I should create
What's the question? How to do it? Parse the text file and use something like useradd to add the accounts, is probably the quickest way.
nate
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Hi,
On Mon, Aug 3, 2009 at 14:49, David Leondleon741210@gmail.com wrote:
I'm trying to avoid typing every password manually. I just need an script that makes the job.
echo "$password" | passwd --stdin "$username"
Obviously, this must be run as root.
HTH, Filipe
David Leon wrote:
I'm trying to avoid typing every password manually. I just need an script that makes the job.
useradd creates the account but still need to setup accpunt's password.
from 'man passwd'
--stdin This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.
I found this
This command is intended to be used in a large system environment where many accounts are updated at a single time (batch mode). Since username and passwords are stored in clear text format make sure only root can read/write the file.
Use chmod command:
# touch /root/batch-user-add.txt # chmod 0600 /root/batch-user-add.txt
Create a user list as follows. Open file:
# vi /root/batch-user-add.txt
Append username and password: user1:password:1001:513:Student Account:/home/user1:/bin/bash user2:password:1002:513:Sales user:/home/user2:/bin/bash user100:password:1100:513:Sales user:/home/user100:/bin/bash tom:password:1110:501:Guest Account:/home/guest:/bin/menu jerry:password:1120:501:Guest Account:/home/guest:/bin/menu
Now create users in batch:
# newusers /root/batch-user-add.txt
On 8/3/09, nate centos@linuxpowered.net wrote:
David Leon wrote:
I'm trying to avoid typing every password manually. I just need an script that makes the job.
useradd creates the account but still need to setup accpunt's password.
from 'man passwd'
--stdin This option is used to indicate that passwd should read the
new password from standard input, which can be a pipe.
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Try this:
while true do read username passwd if [ "$username" == "" ] then exit fi passwd_hash=$(openssl passwd $passwd) echo "Using the following password hash for user "$username": $passwd_hash" /usr/sbin/useradd $username -p "$passwd_hash"; done
use the script like this:
add_multiple_users.sh < /path/to/userlist.txt
Don't forget to make the script executable:
chmod +x add_multiple_users.sh
On Mon, Aug 3, 2009 at 2:56 PM, nate centos@linuxpowered.net wrote:
David Leon wrote:
I'm trying to avoid typing every password manually. I just need an script that makes the job.
useradd creates the account but still need to setup accpunt's password.
from 'man passwd'
--stdin This option is used to indicate that passwd should read the
new password from standard input, which can be a pipe.
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
thanks, I will try this, it looks like what I'm looking for
On 8/3/09, a arias aarias239@gmail.com wrote:
Try this:
while true do read username passwd if [ "$username" == "" ] then exit fi passwd_hash=$(openssl passwd $passwd) echo "Using the following password hash for user "$username": $passwd_hash" /usr/sbin/useradd $username -p "$passwd_hash"; done
use the script like this:
add_multiple_users.sh < /path/to/userlist.txt
Don't forget to make the script executable:
chmod +x add_multiple_users.sh
On Mon, Aug 3, 2009 at 2:56 PM, nate centos@linuxpowered.net wrote:
David Leon wrote:
I'm trying to avoid typing every password manually. I just need an script that makes the job.
useradd creates the account but still need to setup accpunt's password.
from 'man passwd'
--stdin This option is used to indicate that passwd should read the
new password from standard input, which can be a pipe.
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On Mon, Aug 3, 2009 at 3:04 PM, David Leondleon741210@gmail.com wrote:
Hello guys
I have a new Centos 5.3 running, and I have a text file with a bunch of accounts (more than 100) that I should create . File format is like this
user1 pasword1 user2 passwrd2 ....
How can I do this task easier than creating user one by one by hand? Need some help for building an script to achieve this task
Your script may loop over your file using useradd to create users like this:
while true do read username passwd if [ "$username" == "" ] then exit fi useradd $username done
Feed the file into the script as std input, like "./script < file".
As for setting their passwords, the chpasswd command may be what you need.
Chpasswd likes ":" between username and password, while you have spaces in your file. So edit the file and remember to set IFS=: at the beginning of your script.
I usually don't trust enough my own scripting skills. So I'm reluctant to make a script that may radically change the state of my system's user base. You may feel more comfortable making a script which simply builds up and outputs the proper commands, gather this output into a file, give it a good look and only then execute these commands.
Greetings,
On 8/3/09, David Leon dleon741210@gmail.com wrote:
Hello guys
I have a new Centos 5.3 running, and I have a text file with a bunch of accounts (more than 100) that I should create . File format is like this
user1 pasword1 user2 passwrd2 ....
How can I do this task easier than creating user one by one by hand? Need some help for building an script to achieve this task
Thanks David
I have used newusers command in conjunction with a text file in passwd file type fields. man newusers should be your friend here
and if they are to be replicated across nodes as in a cluster, wrap it up in a scrip with scp for /etc/passwd, /etc/group, /etc/shadow and /etc/gshadow
HTH
Thanks and regards
Rajagopal