You Wang | 11ce5f0 | 2017-01-24 17:37:44 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ------------------------------------------------------------------------ |
| 3 | # This script is a workaround for the key collision issue when loging into |
| 4 | # onos cli from both test-station and onos cells with identical user names. |
| 5 | # It copies both private and public keys of localhost (test-station) to |
| 6 | # all remote hosts specified in your cell. |
| 7 | # It also backs up the original keys of the remote hosts before |
| 8 | # overwriting them. |
| 9 | # Setting up passwordless login is recommended before running the script. |
| 10 | # ------------------------------------------------------------------------ |
| 11 | |
| 12 | ADDRESSES=() |
| 13 | # Check if OC1 to OC7 exist |
| 14 | for i in $(seq 1 7); do |
| 15 | if [ -n "$OC$i" ]; then |
| 16 | TEMP=OC$i |
| 17 | ADDRESSES+=(${!TEMP}) |
| 18 | fi |
| 19 | done |
| 20 | |
| 21 | # Check if OCN exists |
| 22 | [ -n "$OCN" ] && ADDRESSES+=($OCN) |
| 23 | |
| 24 | # Copy keys to remote hosts |
| 25 | for address in "${ADDRESSES[@]}"; do |
| 26 | echo "Backing up remote keys on" $address |
| 27 | ssh sdn@$address "cd ~/.ssh; \ |
| 28 | cp id_rsa id_rsa.old; \ |
| 29 | cp id_rsa.pub id_rsa.pub.old; " |
| 30 | |
| 31 | echo "Copying keys to" $address |
| 32 | scp ~/.ssh/id_rsa sdn@$address:~/.ssh/ |
| 33 | scp ~/.ssh/id_rsa.pub sdn@$address:~/.ssh/ |
| 34 | done |