Skip to content

Commit

Permalink
autossh工具收录
Browse files Browse the repository at this point in the history
  • Loading branch information
ppabc committed Aug 4, 2016
1 parent a9e0f55 commit 8061e2e
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 0 deletions.
58 changes: 58 additions & 0 deletions ssh/autossh-master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# autossh
Auto Login SSH Server (expect-based)

# Install

```
$ git clone https://github.com/wufeifei/autossh.git
$ sudo cp autossh/autossh /usr/local/bin/
```

# Config

```
$ cat ~/.autosshrc
server name|192.168.1.110|root|password|port|is_bastion
wufeifei|192.168.1.1|root|password|22|1
```

# Usage

```
$ autossh
############################################################
# [AUTO SSH] #
# #
# #
# [1] 192.168.1.110:feei #
# [2] 10.11.2.103:root #
# [3] 103.21.140.84:root #
# #
# #
############################################################
Server Number:(Input Server Num)
```

OR

```
$ autossh 1
```

OR Auto Sudo

```
$ autossh 3 sudo
```

OR Bastion Host

```
$ autossh 1 10.12.0.123
```

OR Auto Sudo With Bastion

```
$ autossh 1 10.11.0.123 sudo
```
112 changes: 112 additions & 0 deletions ssh/autossh-master/autossh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

# AUTO SSH - Auto Login SSH Server (expect-based)
#
# @category Main
# @package AutoSSH
# @author Feei <[email protected]>
# @license Copyright (C) 2015 Feei. All Rights Reserved
# @link http://github.com/wufeifei/autossh
# @install
#
# $ git clone https://github.com/wufeifei/autossh.git
# $ sudo cp autossh/autossh /usr/local/bin/
# $ 'server name|192.168.1.1|root|password|22|0' > ~/.autosshrc
#
# @usage
# $ autossh // List Server
# $ autossh 1 // Login Num n Server

AUTO_SSH_CONFIG=`cat ~/.autosshrc`
BORDER_LINE="\033[1;31m############################################################ \033[0m"
echo -e $BORDER_LINE
echo -e "\033[1;31m# [AUTO SSH] # \033[0m"
echo -e "\033[1;31m# # \033[0m"
echo -e "\033[1;31m# # \033[0m"
i=0;

if [ "$AUTO_SSH_CONFIG" == "" ]; then
echo -e "\033[1;31m# Config(~/.autosshrc) Not Found # \033[0m";
echo -e "\033[1;31m# # \033[0m"
echo -e "\033[1;31m# # \033[0m"
echo -e $BORDER_LINE
else
for server in $AUTO_SSH_CONFIG; do
i=`expr $i + 1`
SERVER=`echo $server | awk -F\| '{ print $1 }'`
IP=`echo $server | awk -F\| '{ print $2 }'`
NAME=`echo $server | awk -F\| '{ print $3 }'`
LINE="\033[1;31m#"\ [$i]\ $SERVER\ -\ $IP':'$NAME
MAX_LINE_LENGTH=`expr ${#BORDER_LINE}`
CURRENT_LINE_LENGTH=`expr "${#LINE}"`
DIS_LINE_LENGTH=`expr $MAX_LINE_LENGTH - $CURRENT_LINE_LENGTH - 9`
echo -e $LINE"\c"
for n in $(seq $DIS_LINE_LENGTH);
do
echo -e " \c"
done
echo -e "# \033[0m"
done
echo -e "\033[1;31m# # \033[0m"
echo -e "\033[1;31m# # \033[0m"
echo -e $BORDER_LINE

# GET INPUT CHOSEN OR GET PARAM
if [ "$1" != "" ]; then
no=$1
else
no=0
until [ $no -gt 0 -a $no -le $i ] 2>/dev/null
do
echo -e 'Server Number:\c'
read no
done
fi
fi

i=0
for server in $AUTO_SSH_CONFIG; do
i=`expr $i + 1`
if [ $i -eq $no ] ; then
IP=`echo $server | awk -F\| '{ print $2 }'`
NAME=`echo $server | awk -F\| '{ print $3 }'`
PASS=`echo $server | awk -F\| '{ print $4 }'`
PORT=`echo $server | awk -F\| '{ print $5 }'`
ISBASTION=`echo $server | awk -F\| '{ print $6 }'`
FILE='/tmp/.login.sh'
if [ "$PORT" == "" ]; then
PORT=10022
fi
echo '#!/usr/bin/expect -f' > $FILE
echo 'set timeout 30' >> $FILE
echo "spawn ssh -p$PORT -l "$NAME $IP >> $FILE
if [ "$PASS" != "" ]; then
echo 'expect "password:"' >> $FILE
echo 'send '$PASS"\r" >> $FILE
if [ "$2" == 'sudo' ]; then
echo 'expect "@"' >> $FILE
echo 'send "sudo su\r"' >> $FILE
echo 'expect "password for"' >> $FILE
echo 'send '$PASS"\r" >> $FILE
else
if [ "$ISBASTION" == 1 ] && [ "$2" != "" ]; then
echo 'expect ">"' >> $FILE
echo 'send '$2"\r" >> $FILE
echo 'expect "password:"' >> $FILE
echo 'send '$PASS"\r" >> $FILE
if [ "$3" == 'sudo' ]; then
echo 'expect "@"' >> $FILE
echo 'send "sudo su\r"' >> $FILE
echo 'expect "password for"' >> $FILE
echo 'send '$PASS"\r" >> $FILE
fi
fi
fi
fi
echo 'interact' >> $FILE
chmod a+x $FILE
$FILE
echo '' > $FILE
break;
fi
done

0 comments on commit 8061e2e

Please sign in to comment.