문제

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?

도움이 되었습니까?

해결책

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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top