User add on multiple servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User add on multiple servers
# 1  
Old 06-09-2005
User add on multiple servers

I have 85 Unix servers & I need to add single user ID on multiple servers at same time
Can anyone help in this?
I have written one script for single servers.same I need to user for multiple servers



#!/bin/sh

echo Enter user login ID
read loginID

echo Enter Group ID
read GroupID

echo Enter user name & Details
read username

echo Enter Login shell
read shell

share_root=/u/shared
grep $loginID /etc/passwd
if [ $? -ne 1 ]
then
echo 'already in system '
else
echo "Adding user..."
useradd -G $GroupID -c "$username" -m -d /Home/$loginID -s $shell $loginID

echo "Set unix users password..."
passwd $loginID
if
# 2  
Old 06-09-2005
If you have setup for non-interactive login into remote machine with,

1) rsh commands
2) ssh commands
3) expect utility

then you can do it in all machines.

Else exection has to be done in single machines.

hth.
# 3  
Old 06-09-2005
Another posibility is with NFS as, one specific share has to be mounted in all 65 unix machines. With in that you can put user ID, group ID, shell etc.

In the script you have to check whether the user is available or not with id command. If not add them else do nothing. You can cron this script to read from that common NFS file.

hth.
# 4  
Old 06-10-2005
Thanks for your reply.
Actually I want to add user ID on multiple servers thought one single script. I use putty & ssh so I don't have problem for login on all servers. The problem is how to supply user password interactively in script.
# 5  
Old 06-10-2005
Yes. If you want to make this requirement with one script then proper setup has to be done as,

script running machine --> all other machines

which will not need password for ssh authentication. If you don't want to do this, then you have to give password for every authentication.

username="test"
group="group"
hostfile=./hostfile.log

while read server; do
ssh $server "useradd -g $group $username"
done < $hostfile

./hostfile.log will contain all remote server name.

hth.
# 6  
Old 06-10-2005
I would recommend a directory service for your 85 machines, such as NIS or LDAP.
If you still prefer the pain of managing user accounts on 85 machines individually, then:

hth commented with host-based/key-based ssh authentication. You still suffer from providing password for the user account to be added. In this regard, -p option can be used with useradd command. Remember to use encrypted password with -p option. To get encrypted password, perl function crypt can be used.

I bet you would not say password encryption algorithm varies from machine to machine and it is standard unix cryption.

Hope helpful,
Tom
# 7  
Old 06-10-2005
... on the assumption that you have a homogenous Unix environment, you could always just try appending the user's password line into /etc/shadow on the remote machine ...

Code:
1. encrypt the user's password on the local machine
passwd newuser

2. copy the user's password line from /etc/shadow into a tempfile
grep newuser /etc/shadow > /tmp/file 

3. scp the tempfile over to the remote host
scp /tmp/file remhost:/tmp/file

4. ssh to the remote host and cat the tempfile into /etc/shadow and then remove the tempfile
ssh remhost "cat /tmp/file >> /etc/shadow; rm /tmp/file"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Script To Delete User Accounts On Multiple Servers

Hello All, The servers in question are AIX/Unix servers. I was hoping to find a scripting solution where I could use one server as a jump server and run a script that would check each server for a user account (the source file for the user accounts would be a text file or csv file) , and delete... (4 Replies)
Discussion started by: k45bryant
4 Replies

3. Shell Programming and Scripting

Script to add new users to a group on multiple servers using SSH

Hi Experts, I am new to scripting. We have around 400 Linux servers in our environment. I want to add a new user to a perticular group on all the servers using SSH. Requirements: 1) Need to take the server names from a text file. 2) Login into each server and check whether perticular... (1 Reply)
Discussion started by: Satya1983
1 Replies

4. Shell Programming and Scripting

Prevent wrong user from using shell script for multiple remote servers

Hi, I am running a shell script from a central server to multiple remote servers using the following code: application_check() { # Linux/UNIX box with ssh key based login SERVERS=`cat /tmp/server-details` # SSH User name USR="user" # create new file > /tmp/abc.log # connect... (2 Replies)
Discussion started by: mystition
2 Replies

5. Shell Programming and Scripting

user id creation of multiple servers

Need help in creating a user with passord in mulptiple solaris servers using a script.. (0 Replies)
Discussion started by: ningy
0 Replies

6. UNIX for Dummies Questions & Answers

How to add user to multiple groups

hi all i am new to solaris how to add a user to multiple(secondary) groups. user :anna Groups : delhi ,mumbai,pune i need like this in cat /etc/group delhi::anna mumbai::anna pune::anna i tried using usermod -a -G hyd anna that does int work how to delete user from group... (3 Replies)
Discussion started by: kalyankalyan
3 Replies

7. UNIX for Advanced & Expert Users

Help Me - How to grep in multiple servers

Hi All, I need help , Regarding the keyword search in multiple servers at a time . we are desiging a search website . we have a multiple servers and each of the server have 3 instances having Unix compressed files.Our requirement was we need to search the particular key word for eg. we need to... (7 Replies)
Discussion started by: prasad00124
7 Replies

8. Shell Programming and Scripting

script to change passwords for the same user on multiple servers

I am trying to write a script to change passwords for the same user on multiple servers. My environment runs purely ssh / scp not rsh / rcp and therefore coping using rcp is not an option. I have been playing with expect to perform tasks but think there must be a better way. Has anyone got... (7 Replies)
Discussion started by: stolz
7 Replies

9. Shell Programming and Scripting

rsh to change multiple ip in multiple servers?

good day. i jsut wanted to know what is the best script or the best way changing a lot of Ip's in all servers. Do you have any idea? im using awk to change IP,what if, you have lots of servers. You need to change it one by one? It will take time to change it manually. (2 Replies)
Discussion started by: kenshinhimura
2 Replies

10. Shell Programming and Scripting

ftp to multiple servers

Hi folks. I am writing a ksh ftp script. The problem is, I need to transfer the files to several different servers. Is there a way to close a connection and move on to the next in one script or do I need to write a separate script for each one? Thanks, kristy (2 Replies)
Discussion started by: kristy
2 Replies
Login or Register to Ask a Question