Useradd on 200 servers from one server.

I have a list of around 250 machines(IPs).

I have few lines of task on each machine like adding users.
I don't want to logon to each machine and then change.

Can anybody help me getting logic to do it from one machine through SSH, where I can hardcode the password as well as other tasks.

Have you tried somethin like clusterssh? Altough more than 200 servers are a lot even with a tool like that.

1 Like

You can use SSH to execute commands remotely, have a look at the manual. You'll need to use either expect or sshpass to parse the password. In any case, it's always better to connect using an ssh-key.

While this won't help for all tasks you might want to achieve, you should consider some centralized administrative repository for user management, like NIS or LDAP. Adding or modifying user's account would then need to be done just once. Not to mention password synchronization.

1 Like

If you put the public SSH key on each of the servers, then you will be able to have password-less authentication to run the commands. Do you know how to generate the keys and what to do with them?

If you are running as the root user, then you will need to make sure that the /etc/ssh/sshd.conf configuration file permits root login. There are a number of options to consider and balance against the risks.

I'm afraid that there is no easy way to get them onto each server - it will be a manual task, but the investment of time in a one off action.

Note
When you are adding your users, you will need to make sure that their UID is unique too. Some servers will object if you try to add a user with a specific UID that already exists. You could get away with not specifying the UID, but then if you are NFS sharing files (or moving them keeping original permissions) then you will all sorts of problems because files are owned by the UID not the alphabetic userid.

I agree with jlliagre that you would be better to use NIS (historically also known as YP) or LDAP. Once set up, that would cut down the administration effort.

Robin

1 Like

Thanks All for your contribution, especially rbatte1
I tried expect, but it's tricky to code, I heard about Func, it's easier to do.
I will try Func.

---------- Post updated at 05:08 AM ---------- Previous update was at 05:08 AM ----------

LDAP or NIS is not an option in this case :frowning:

If it was me, I would write a PHP script to do this. Basically you would have a configuration file with the hostnames and other required information; then you can write a PHP script to read the configuration file, do the tasks on the servers, and log any errors or the results.

For SSH from PHP you might consider phplibsec

With a PHP solution, you could then create a secure web-interface to help with the tasks.

1 Like