perl-5.22
|
Last change
on this file since 3187b26 was
c5c522c,
checked in by Edwin Eefting <edwin@datux.nl>, 9 years ago
|
|
initial commit, transferred from cleaned syn3 svn tree
|
-
Property mode set to
100755
|
|
File size:
996 bytes
|
| Rev | Line | |
|---|
| [c5c522c] | 1 | #!/bin/bash |
|---|
| 2 | # Ssh keyfix version 2.0 |
|---|
| 3 | |
|---|
| 4 | if [ -z $1 ]; then |
|---|
| 5 | echo "Usage: $0 user@host" |
|---|
| 6 | echo "Installs your public ssh key to host, if neccesary" |
|---|
| 7 | exit 1 |
|---|
| 8 | fi |
|---|
| 9 | |
|---|
| 10 | if [ ! -f ~/.ssh/id_rsa ]; then |
|---|
| 11 | ssh-keygen -N "" -b 2048 -t rsa -f ~/.ssh/id_rsa || exit 1 |
|---|
| 12 | fi |
|---|
| 13 | |
|---|
| 14 | PUB="`cat ~/.ssh/id_rsa.pub`" || exit 1 |
|---|
| 15 | |
|---|
| 16 | echo -n "Checking ssh key on $1..." |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | checkkey() |
|---|
| 20 | { |
|---|
| 21 | ssh $OPTS $1 " |
|---|
| 22 | mkdir ~/.ssh &>/dev/null |
|---|
| 23 | if ! grep '$PUB' ~/.ssh/authorized_keys &>/dev/null; then |
|---|
| 24 | echo -n 'Installing public key...' |
|---|
| 25 | echo '$PUB' >> ~/.ssh/authorized_keys |
|---|
| 26 | fi" |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | checkkey $1 |
|---|
| 30 | EXIT=$? |
|---|
| 31 | |
|---|
| 32 | #remove hostkey and retry |
|---|
| 33 | if [ $EXIT == 255 ]; then |
|---|
| 34 | TARGETHOST=`echo $1 | sed s/.*@//` |
|---|
| 35 | echo -n "SSHKEYFIX: Removing hostkey of $TARGETHOST..." |
|---|
| 36 | cat ~/.ssh/known_hosts | grep -v "^$TARGETHOST " > ~/.ssh/known_hosts.$$ || exit 1 |
|---|
| 37 | mv ~/.ssh/known_hosts.$$ ~/.ssh/known_hosts || exit 1 |
|---|
| 38 | echo "OK" |
|---|
| 39 | checkkey $1 |
|---|
| 40 | EXIT=$? |
|---|
| 41 | fi |
|---|
| 42 | |
|---|
| 43 | if [ $EXIT == 0 ]; then |
|---|
| 44 | echo "OK" |
|---|
| 45 | exit 0 |
|---|
| 46 | else |
|---|
| 47 | echo "ERROR!" |
|---|
| 48 | exit 1 |
|---|
| 49 | fi |
|---|
Note: See
TracBrowser
for help on using the repository browser.