S
S
Sergey2017-07-31 19:06:48
linux
Sergey, 2017-07-31 19:06:48

How to scatter public keys with xargs, ssh-copy-id and sshpass?

I recently received a pack of 500+ servers that need to be managed in bulk, run the same tasks via ssh, etc. First you need to go through and upload public ssh keys for passwordless login. I prepared a csv file with the data of servers like: ip
; password
ip; password
ip; password
cut -f 2 -d ';' /tmp/111/list.txt

cut -f 2 -d ';'  /tmp/111/list.txt | xargs  -I "%" sshpass -p % ssh-copy-id ./key [email protected]/code>
И теперь никак не соображу, как вместо ХХХХ подставить соответствующие паролям айпишники?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2017-07-31
@saboteur_kiev

while read
do
  IP=`echo $REPLY|cut -d ";" -f 1`
  PW=`echo $REPLY|cut -d ";" -f 2`
  echo "sshpass -p ${PW} ssh-copy-id [email protected]${IP}"
done < list.txt

Try like this.
If echo works correctly, then just fix it to execute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question