Restoring ssh connections on resume

I use pm-utils for hibernation support.
It has a hooks system which can execute stuff upon hibernate/suspend/thaw/resume/..., but they run as root.
If you want to run stuff as a regular user you could do something like

  1. su $user -c <command>

..but these commands have no access to your user environment.
In my user environment I have a variable which I need access to, namely SSH_AUTH_SOCK, which points to my agent which has some unlocked ssh keys. Obviously you don't want to reenter your ssh key passwords everytime you resume.
(In fact, I started using hibernate/resume because I got tired of having to enter 4 passwords on boot. - 1 for dm_crypt, 1 for login, 2 for ssh keys, not because it is much faster)

The solution is very simple. Use this:

  1. sudo pm-hibernate && do-my-stuff.sh

This way, do-my-stuff.sh will be executed when you resume, after the complete environment has been restored.
Ideal to kill old ssh processes, and setup tunnels and ssh connections again.
I'm probably gonna integrate this into my microDE

Trackback URL for this post:

http://dieter.plaetinck.be/trackback/85
Submitted by Dieter_be on Wed, 06/16/2010 - 18:11. categories [ ]

Why don't you just use

Why don't you just use autossh?

I want the possibility to

I want the possibility to fallback to other hosts in case of unreachability. So that it would try hosts from a list in a specific order.
Afaik autossh does not support this. But it looks like a good tool otherwise, think I'm gonna get in touch with the author :)

pam_mount

You can use pam_mount authentication module to mount/umount encrypted partitions with single login/logout.

Yeah, and using pam_ssh I

Yeah, and using pam_ssh I can login by unlocking an ssh key, but I prefer this approach because this way I only need to enter 1 password :)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Security question, designed to stop automated spam bots