If you are a user of serveral servers and want to simplify the process everytime you login, then you will love this trick.
computerInfo.ini
file to store your login informationcd .shh
touch computerInfo.ini
vim computerInfo.ini
i
to enter edit mode
Put in ip port user_name password name_of_server
, separate your account in different lines
For example:
#ip port user password description 130.102.72.25 22 s4XXXXXX password goliath 192.12.76.251 22 s4XXXXXX password flashlite
core.ex
file to mimic the pipeline of entering information#!/usr/bin/expect set ip [lindex $argv 0] set port [lindex $argv 1] set username [lindex $argv 2] set password [lindex $argv 3] set timeout -1 spawn ssh -p $port $username@$ip expect { "password" {send "$password\r";} "yes/no" {send "yes\r";exp_continue} } interact
login.sh
to decrypt both core.ex
and computerInfo.ini
filetouch login.sh
vim login.sh
i
Put the text below in the login.sh
file
#!/bin/bash file="computerInfo.ini" awk '{if (NR > 1 && $1 != ""){printf "%-2s %-45s %-15s \n","("NR-1")",$5,$1}}' $file echo "please choose which machine to login:" read number number=$[number+1] read ip port user password <<< $(echo `awk 'NR=="'$number'"{print $1,$2,$3,$4}' $file`) ./core.ex $ip $port $user $password
Don't forget to chmod 777 [file]
all these 3 files respectively
expect
Notice that core.ex
file can only be run with expect
brew install expect
Put alias login='/Users/apple/.ssh/login.sh'
in .bashrc
and .zshrc
source .bashrc
and source .zshrc
login
to see what you can get!