I have 100+ devices that has same username and password and enabled SSH.

What I would like to achieve is for each device I want to run same command to change their password bulk.

What I did is to create 2 files; first one contains hosts, second one contains commands.

Hosts file example;

Commands file;

passwd -a des
grep -v users.1.password= /tmp/system.cfg > /tmp/system.cfg.new
echo users.1.password=`grep %user% /etc/passwd | awk -F: '{print $2}'` >> /tmp/system.cfg.new
cfgmtd -f /tmp/system.cfg.new -w

I tried following command but its failing because of 2 reasons;

1 - It asks me to allow self-signed key everyime. 2 - It does stuck on input part

for host in $(cat hosts.txt); do ssh -u username@"$host" -pPasswd command.txt >"output.$host"; done

So basically I want to connect all device (they all have different self signed certificate) and change their password accordingly.



I would use ansible. Ansible is used specifically to run commands using SSH over multiple devices. You can run one command at a time using ansible shell or multiple commands sequenced together using ansible playbook.

If you don't want to install, setup and run ansbile I would do this as a two part step. Once script to scp the script over to all the hosts (perhaps the /tmp directory). Then a second to run the script. Make sure the script is backgrounded (nohup) and logs output in the local device. Perhaps a 3rd script to check the logs/success.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.