1

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;

192.168.1.20
192.168.1.21
192.168.2.30
192.168.2.31

Commands file;

passwd -a des
%new-password%
%new-password%
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
exit

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.

Thanks!

1 Answer 1

0

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.