user3331975
user3331975

Reputation: 2805

multiple passwords in sshpass

Is there a way to try multiple passwords when using sshpass command? I have a txt file named hosts.txt listing multiple system IPaddresses and each system uses different passwords (for example - 'mypasswd', 'newpasswd, nicepasswd'). The script reads the hosts.txt file and execute a set of commands on each system. Since I don't know which system uses which of these given passwords, i wanted to try all these set along with sshpass command and execute the script with the password that works.. Is that possible?

#!/bin/bash

while read host; do
  sshpass -p 'mypasswd' ssh -o StrictHostKeyChecking=no -n root@$host 'ls;pwd;useradd test'
done < hosts.txt

Upvotes: 0

Views: 3027

Answers (1)

fejese
fejese

Reputation: 4628

Instead of trying to get password based authentication, isn't it an option to setup key based auth? You can then either add your one public key to ll systems or optionally generate different ones and use the -i keyfile option or create an entry in the ssh configuration file as below.

Host a
  IdentityFile /home/user/.ssh/host-a-key

Upvotes: 0

Related Questions