![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SFTP Transfer Across Multiple Servers | Cameron | Shell Programming and Scripting | 0 | 05-20-2008 06:08 AM |
| rsh to change multiple ip in multiple servers? | kenshinhimura | Shell Programming and Scripting | 2 | 02-18-2008 12:04 AM |
| script to change passwords for the same user on multiple servers | stolz | Shell Programming and Scripting | 6 | 12-18-2007 10:08 AM |
| moving files across multiple servers | kymberm | UNIX for Advanced & Expert Users | 2 | 10-23-2002 09:04 AM |
| ftp to multiple servers | kristy | Shell Programming and Scripting | 2 | 12-03-2001 12:49 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
... 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" |
||||
| Google The UNIX and Linux Forums |