Stop a ssh-agent started on a remote pty on logout.
This commit is contained in:
parent
c1c00f1b62
commit
f76b8860cf
1 changed files with 15 additions and 2 deletions
17
.bash_logout
17
.bash_logout
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting.
|
#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting.
|
||||||
|
|
||||||
# Clear the screen/console on logout.
|
# Clear the screen/console on logout.
|
||||||
if (( $SHLVL == 1 )); then
|
if (( SHLVL == 1 )); then
|
||||||
if [[ -x /usr/bin/clear_console ]]; then
|
if [[ -x /usr/bin/clear_console ]]; then
|
||||||
/usr/bin/clear_console -q
|
/usr/bin/clear_console -q
|
||||||
elif [[ -x /usr/bin/clear ]]; then
|
elif [[ -x /usr/bin/clear ]]; then
|
||||||
|
|
@ -9,6 +9,19 @@ if (( $SHLVL == 1 )); then
|
||||||
elif [[ -x /usr/bin/tput ]]; then
|
elif [[ -x /usr/bin/tput ]]; then
|
||||||
/usr/bin/tput clear
|
/usr/bin/tput clear
|
||||||
else
|
else
|
||||||
echo -ne "\E[2J"
|
echo -ne "\e[2J"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
hash ssh-add ssh-agent >/dev/null 2>&1 && {
|
||||||
|
# Stop any started ssh-agent as long as the shell level is 1 and we're not on a tty.
|
||||||
|
(( SHLVL == 1 )) && [[ "$(tty)" == /dev/pts/* ]] && [[ -n "$SSH_AGENT_PID" ]] && {
|
||||||
|
ssh-agent -k
|
||||||
|
(( $? != 0 )) && printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to stop ssh-agent." >&2
|
||||||
|
sleep 5
|
||||||
|
unset SSH_AGENT_PID SSH_AUTH_SOCK
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update the ~/.ssh/agents file.
|
||||||
|
__read_ssh_agents && __write_ssh_agents
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue