0

So I know that to enable Passwordless SSH I need to generate a public authentication key and append it to the remote hosts ~/.ssh/authorized_keys file, generating a new SSH key pair.

The question is can I have an array of passwords and try one after another until the right password is found or do I need to have actual pairs? so knowing which host has what password. reason: I have thousands of hosts and I don't know what host has what password but I do have all possible passwords list.

I want to use GNU parallel to ssh but for that I need a Passwordless SSH.

I guess another option would be to run in parallel my script that tries different passwords until success.

3
  • 1
    I doubt that will work. Why not just create your public key and copy it to all the hosts, or, if you're using networked home directories, you'll only need to copy it once (using ssh-copy-id). Dec 9, 2020 at 1:28
  • Does this answer your question? Check which users have specific password
    – Panki
    Dec 9, 2020 at 8:12
  • Thank you for the clue but it does not seem to relate to my question @Panki
    – dwt.bar
    Dec 9, 2020 at 12:47

1 Answer 1

3

sshpass does that.

You can run this on a trusted system (e.g. no attackers: The passwords will be shown in cleartext if another user runs ps).

testone() { sshpass -p "$1" ssh "$2" echo OK; }
export -f testone
parallel --tag -k testone :::: passwords.txt hostlist.txt 2>/dev/null

Be aware that some systems will see this as an attack and thus lock you out for a period if you guess wrongly 3 times in a row. So you should keep track of your successes and remove them from hostlist.txt.

1
  • @ole.tange.dk would it work if I would write an if statement within testome() to prevent further iterations for a particular host if the first iteration provided with a certain result? code example: testone() { result=sshpass -p "$1" ssh "$2" echo OK; if [[ $result == "denied" ]]; then exit; fi } export -f testone parallel --tag -k testone :::: passwords.txt hostlist.txt 2>/dev/null
    – dwt.bar
    Dec 15, 2020 at 4:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .