When you have 100+ routers or servers you manage, it is a bit tedious to make a configuration change to all of them manually, especially when that change is exactly the same for all of them. There is tons of software for this scenario. I have used a few different ones in the past, but parallel-ssh (formerly pssh) is what I use for Mikrotik.
Example: Need to enable and set primary and secondary ntp servers on 100 devices. First you need to create a text file with all your devices IP addresses, and optionally port and username.
10.10.10.1:22
10.10.10.2:22
10.10.10.3:22
save it as ips.txt for instance, and use the command bellow to blast commands to all listed devices.
parallel-ssh -l admin -x "-o StrictHostKeyChecking=no" -A -h /home/sam/ips.txt -v -t 10 -o /home/sam "/system ntp client set mode=unicast enabled=yes primary-ntp=1.2.3.4 secondary-ntp=1.2.3.5"
Explanation:
-l Specify the user here instead of txt file
-A Prompt for password
-h Location of host file
-o Output results to this directory (will create individual file per node)
-x ssh arguments, see 'man ssh' StrictHostKeyChecking=no is required if you haven't accepted the keys for the hosts previously
See man parallel-ssh for further details
If you get timeouts, it may be because you haven't saved or 'trusted' the server's key.
Error 255 may indicate failed login attempt
UPDATE: To remove the need for saving / trusting keys, edit /etc/ssh/ssh_config and add these 2 lines underneath the line 'Host *'
UserKnownHostsFile=/dev/null
StrictHostKeyChecking no
This will bypass the need to hit 'yes'.
Example: Need to enable and set primary and secondary ntp servers on 100 devices. First you need to create a text file with all your devices IP addresses, and optionally port and username.
10.10.10.1:22
10.10.10.2:22
10.10.10.3:22
save it as ips.txt for instance, and use the command bellow to blast commands to all listed devices.
parallel-ssh -l admin -x "-o StrictHostKeyChecking=no" -A -h /home/sam/ips.txt -v -t 10 -o /home/sam "/system ntp client set mode=unicast enabled=yes primary-ntp=1.2.3.4 secondary-ntp=1.2.3.5"
Explanation:
-l Specify the user here instead of txt file
-A Prompt for password
-h Location of host file
-o Output results to this directory (will create individual file per node)
-x ssh arguments, see 'man ssh' StrictHostKeyChecking=no is required if you haven't accepted the keys for the hosts previously
See man parallel-ssh for further details
If you get timeouts, it may be because you haven't saved or 'trusted' the server's key.
Error 255 may indicate failed login attempt
UPDATE: To remove the need for saving / trusting keys, edit /etc/ssh/ssh_config and add these 2 lines underneath the line 'Host *'
UserKnownHostsFile=/dev/null
StrictHostKeyChecking no
This will bypass the need to hit 'yes'.
Comments
Post a Comment