SSH Maker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
#!/bin/bash SSH_PATH=~/temp/server echo "Please make sure you have install 'bash' and 'expert'!" echo "Please enter the name of file you need to create, e.g. 'google-ssh'" read FILE_NAME echo "Please enter the path you want to save, default value '${SSH_PATH}'" read TEMP_PATH if [ ! -z "$TEMP_PATH" ] then SSH_PATH="$TEMP_PATH" fi if [ ! -d "${SSH_PATH}" ] then mkdir -p ${SSH_PATH} fi if [ -f "${SSH_PATH}/${FILE_NAME}.sh" ] then echo "The file ${FILE_NAME}.sh has existed at the ${SSH_PATH}" echo "what do you want to do?" echo "1 delete the exist file" echo "2 change the exist file name to ${FILE_NAME}2.sh" read EXIST_FILE if ["${EXIST_FILE}" -eq 1] then rm -f ${SSH_PATH}/${FILE_NAME}.sh else mv ${SSH_PATH}/${FILE_NAME}.sh ${SSH_PATH}/${FILE_NAME}2.sh fi fi echo "Please select the method of SSH connect and enter the digit:" echo "1 Password" echo "2 Key" read SSH_METHOD echo "Please enter the server of SSH:" read SSH_SERVER echo "Please enter the port: (defealt 22)" read TEMP_PORT if [ -z "$TEMP_PORT" ] then TEMP_PORT=22 fi PORT="${TEMP_PORT}" case ${SSH_METHOD} in 1) echo "Please enter the username:" read SSH_USER echo "Please enter the password:" read SSH_PASS echo "#!/usr/bin/expect spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -p $PORT ${SSH_USER}@${SSH_SERVER} expect 'password:' send \"${SSH_PASS}\r\" interact" >> ${SSH_PATH}/${FILE_NAME}.sh ;; 2) echo "Please enter the username:" read SSH_USER echo "Please enter the full path of the private key, e.g. ~/temp/server/test.pem" read SSH_KEY echo "#!/bin/sh ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -i \"${SSH_KEY}\" ${SSH_USER}@${SSH_SERVER}" >> ${SSH_PATH}/${FILE_NAME}.sh ;; *) echo "INVALID METHOD!" ;; esac chmod +x ${SSH_PATH}/${FILE_NAME}.sh ${SSH_PATH}/${FILE_NAME}.sh |
SSH Connector
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/bin/bash #Please make sure you have install "bash" and "expert"! SSH_PATH=~/temp/server chmod -R 777 ${SSH_PATH} path="" # could set to any absolute path declare -a array=( "${SSH_PATH}"/*.sh ) j=1 for i in "${array[@]}" do echo "$j $i" | sed "s#${SSH_PATH}/##" ((j++)) done echo "Please select which server you want to connect:" read server server=$((server-1)) echo "You will connect to ${array[server]} now!" ${array[server]} |