SSH Tools
This is a collection of bash shell scripts that make SSH more convenient. To make these functions available, simply source the script from ${HOME}/.bashrc.
The script contains four main functions:
check_ssh_agent
This function is useful when wanting to use passworded SSH keys with an SSH Agent. Calling this function will see if there is a running SSH Agent for the current user and will attach it to the shell this is called from.
sshpw
This function will check to make sure any passworded SSH keys are available via the SSH agent. If they are not unlocked, the user will be prompted to enter a password. To use this function, alias ssh to sshpw:
alias ssh='sshpw'
sshb / sshbk
SSH is able to share connections to the same host. When you connect to a host for the first time, SSH will create a tunnel that subsequent connections can use to connect. The advantage of this is that subsequent connetions to the same host are lightning fast.
The best way to set this up is by creating an alias for the host in your ${HOME}/.ssh/config file:
Host nickname Hostname <hostname or IP here> ControlMaster auto ControlPath /tmp/%r@%h:%p
Once the nickname is setup, you can use it to connect to the host.
ssh nickname
Now any new connection in another shell will piggyback off this connection. The problem with such a setup is that you cannot close the main window or else you will kill off all your other connections. These two shell functions will initiate a connection to the given server and put it in the background. That way there is no shell taking up space just for the shared connection master. The following will put the connection in the background.
sshb nickname
Subsequently, killing off the background process can be done using:
sshbk nickname