Question

I have 20 machines where I need to create a user and set his password. I can create the accounts and set the passwords using a for loop. The inside of the for loop is given as follows

ssh -t user1@$node_name 'sudo useradd user2'

ssh -t user1@$node_name 'sudo passwd user2'

However, this requires me to input the password for user1 first and then input the new password for user2. I tried it for 2 machines and it works. I however do not like the wasteful effort involved and am guessing there would me a more efficient way of doing so. Any ideas?

Was it helpful?

Solution

To remove the need to enter user1's password, you can mess with the sudo -A or -a options on $node_name to get authentication to happen automatically in some other way.

To remove the need to type user2's password, you can try something like this:

ssh -t user1@$node_name "sudo echo $newpass | useradd user2 --stdin"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top