View previous topic :: View next topic |
Author |
Message |
Alrua n00b
Joined: 01 Feb 2004 Posts: 45
|
Posted: Sat May 20, 2006 6:01 pm Post subject: TIP: Automatic keychain on shell spawn |
|
|
I found the following snip of code useful to automatically run keychain every time a shell is spawned, and so I though I'd share it.
Instead of just blindly running the keychain program (which caused a perceptible lag when starting up konsole for me), it checks if keychain has already created its files and if so, sources it. Afterwards it checks (through ps) if there's actually an ssh-agent running with the pid from the keychain file. If not, keychain is re-run and its file re-sourced.
Just put the following code somewhere in your .bashrc and replace <key-file> with the filename of your private key.
Code: |
if [ $TERM != "dumb" ]; then
if [ -f /usr/bin/keychain ]
then
if [ ! -f ~/.keychain/$HOSTNAME-sh ]
then
/usr/bin/keychain ~/.ssh/<key-file>
fi
source ~/.keychain/$HOSTNAME-sh
if ! /bin/ps -p $SSH_AGENT_PID > /dev/null
then
/usr/bin/keychain ~/.ssh/<key-file>
source ~/.keychain/$HOSTNAME-sh
fi
fi
fi
|
For those using multiple keys, this might be combined with the keychain-autoloader found here: https://forums.gentoo.org/viewtopic-t-459392.html
I hope someone else finds this useful |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|