Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use keychain to load and handle the agents, it's much better equipped…
… to handle it.
- Loading branch information
Showing
1 changed file
with
1 addition
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1 @@ | ||
# | ||
# File: ~/.ssh/ssh-login | ||
# | ||
# Checks authentication environment. | ||
# If the ssh-agent is not running, starts a new one. | ||
# | ||
# Setup instructions: | ||
# | ||
# 1) For bash and ksh users: | ||
# | ||
# Include the following in your ~/.bashrc or ~/.kshrc: | ||
# | ||
# . $HOME/.ssh/ssh-login | ||
# | ||
# Note, The common error is to instead include this command to ~/.bash_profile file. | ||
# The authentication method of any subsequent non-login shell sessions | ||
# started will not be supplied by the running ssh-agent which | ||
# only calls ~/.bashrc for their shell session setup. The startup | ||
# of the login shell session includes a call to ~/.bashrc anyway. | ||
# | ||
# | ||
# | ||
# 2) For csh and tcsh users: | ||
# | ||
# Include the following in your ~/.cshrc or ~/.tcshrc | ||
# | ||
# source $HOME/.ssh/ssh-login | ||
# | ||
# | ||
|
||
HN=`hostname` | ||
SSH_ENV=$HOME/.ssh/env-$HN | ||
|
||
function ssh_clean { | ||
d="$HOME/.ssh" | ||
|
||
f0=$d/known_hosts | ||
f1=$d/known_hosts_tmp | ||
|
||
cat /dev/null > $f1 | ||
|
||
while read host line; do | ||
if [ $host != "localhost" ]; then | ||
echo $host $line >> $f1 | ||
fi | ||
done < $f0 | ||
|
||
mv $f1 $f0 | ||
|
||
chmod 644 $f0 | ||
} | ||
|
||
|
||
# Initialize new agent and add authentication | ||
function start_agent { | ||
|
||
|
||
# Start authenticating daemon | ||
# No authentications set up yet, just starting daemon! | ||
ssh-agent | head -2 > ${SSH_ENV} | ||
chmod 600 ${SSH_ENV} | ||
|
||
# Find SSH_AUTH_SOCK and SSH_AGENT_PID of the available daemon | ||
. ${SSH_ENV} > /dev/null | ||
|
||
# Add authentication to this and only this daemon | ||
if [[ -f $HOME/.ssh/id_dsa ]]; | ||
then | ||
for i in `ls $HOME/.ssh/id_dsa*`; | ||
do | ||
if ! echo $i | grep -E '\.(pub|keystore)' &>/dev/null; | ||
then | ||
ssh-add $i; | ||
fi; | ||
done; | ||
fi; | ||
} | ||
|
||
|
||
if [[ -f "$SSH_ENV" ]]; | ||
then | ||
# Find SSH_AUTH_SOCK and SSH_AGENT_PID of the available daemon | ||
source ${SSH_ENV} > /dev/null | ||
|
||
# Check if the agent is still running | ||
ierr=0 | ||
ps ${SSH_AGENT_PID} > /dev/null || ierr=1 | ||
|
||
if [[ $ierr == "0" ]]; then | ||
echo > /dev/null | ||
else | ||
# If not initialize new agent and | ||
# add authentication | ||
start_agent; | ||
fi | ||
else | ||
start_agent; | ||
fi | ||
|
||
# Clean localhost entry in the known host file | ||
ssh_clean | ||
eval `keychain --eval --agents ssh id_dsa` |