View Single Post
  #4 (permalink)  
Old 17-05-2007, 01:52 AM
nixcraft's Avatar
nixcraft nixcraft is offline
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

I’ve two solutions for you. Here is my shell script:
Solution # 1 Shell script
sshconnect.sh
Code:
#!/bin/bash
PROFILES=~/.ssh.profiles
aindex=1
hosts=( null )
# read array
function readHosts(){
 exec 3<&0
 exec 0<$PROFILES
 while read line
 do
    rline=$(echo $line | egrep -v "^#" | sed '/^$/d')
    if [ "$rline" != "" ]; then
        user=$(echo "$rline" |  awk -F'|' '{ print $1}')
        ip=$(echo "$rline" |  awk -F'|' '{ print $2}')
        port=$(echo "$rline" |  awk -F'|' '{ print $3}')
        [ "$port" == "" ] && port=22 || :
        hosts[$aindex]=$(echo "ssh -p$port $user@$ip")
        aindex=` expr $aindex + 1 `
    fi
 done
 exec 0<&3 
}
# display choice and connect to server
function displayHosts(){
  echo "------------------------------------"
  echo "Sr# : SSH Server Host Name"
  echo "------------------------------------"
  for (( i=1; i<$aindex; i++ ))
  do
        echo "#$i : ${hosts[$i]}"
  done
  read -p "Enter host number: " myHostNumber
  echo "Connecting to ${hosts[$myHostNumber]} ..."
  ${hosts[$myHostNumber]}
}

readHosts
displayHosts
Above is my script
~/.ssh.profiles file - stores SSH Username | IP and Optional port number:
Code:
#format USER|IP|Port
usr1|192.168.1.1|22
usr2|192.168.1.2
usr3|192.168.1.3
vivek|vpn.nixcraft.in|555
All you have to do is copy above two files and customize ~/.ssh.profiles file and run script as follows:
Code:
chmod +x sshconnect.sh
Run as
Code:
./sshconnect.sh
You will get
Code:
------------------------------------
Sr# : SSH Server Host Name
------------------------------------
#1 : ssh -p22 usr1@192.168.1.1
#2 : ssh -p22 usr2@192.168.1.2
#3 : ssh -p22 usr3@192.168.1.3
#4 : ssh -p555 vivek@vpn.nixcraft.in
Enter host number: 4
Connecting to ssh -p555 vivek@vpn.nixcraft.in ...
Solution # 2 GUI tools
If you want GUI tool i recommend gpass; see image below. You can just select host and connect it




It is upto you which solution you want to use. See Linux password manager that also works under Windows / OS X | nixCraft
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote