Using ssh-agent
and private keys per the usual. Everything's working as normal.
My question regards best practices on flushing keys from ssh-add
on activity like sleep, suspend, hibernate, etc. I thought about writing a simple wrapper around those commands, but then wondered if are they even called? Or does the kernel initiate this activity directly? Are the PM utilities strictly userland?
I would like this additional layer of security beyond locking my screen, etc. and was wondering if anyone else had solved this elegantly or has best practices to recommend. Thanks.
You might be able to have a user daemon listen for the status change over D-Bus. It looks like gnome-power-manager doesn't expose any signals for this, but you might be able to get something from hal or DeviceKit-power/upower.
I have a little
pm
script that run's user-defined scripts for each logged in user on suspend/hibernate, resume/thaw. I've used this to kill or restart processes that don't behave well over suspend. User's can create scripts in~/.user-pm
which are run in lexicographic order on suspend and reverse order on resume.$1
has the pm operation name.You could simply add a user-script that calls "
ssh-add -D
" on suspend/hibernate. (you'll have to look up theSSH_AUTH_SOCK
somewhere, but I assume you'd need that for any solution).Here's the global
pm
hook:I'm on ubuntu - this should work for debian too - otherwise, YMMV
If you add your key using the "-c" option to "ssh-add", it requires that you confirm every use. This isn't as good as removing the key from your agent on suspend, if you also lock your screen it can have a similar effect, since the key use can't be confirmed until you login.
In the past I accomplished this key removal by running a simple script that woke up every few seconds and looked for the program that locks the screen, and if it was found it would do the "ssh-add -D". Then once it went away, it would invoke the "ssh-add -c" again to ask me for the password. I ended up switching to just relying on confirmation and screen locking when I suspend or leave the keyboard.
Thanks @Greg for your answer, I took the liberty of expanding on it to make it more "freedesktop" compliant, since pm-utils is a freedesktop.org project.
This script now will work in
config.d
,power.d
, andsleep.d
with a copy or a symlink. It'll then look for scripts to run in~/.config/pm/
using the same folder names (config.d
,power.d
, andsleep.d
) as/etc/pm
.Then this is my script to remove all keys from the
ssh-agent
on suspend/hibernate, and re-add a key used for SparkleShare. Just to be sure, it also checks for otherssh-agent
s and removes all the keys from them.This is another indirect solution that doesn't involve flushing registered identities/keys from the agent, but would locking the ssh-agent be just as useful (
ssh-add -x
)? I am unsure how secure this method would be (certainly no where near as secure as removing keys from the agent), however I assume this feature was implemented to offer the kind of added security you are looking for in this situation.