Linux- passwordless ssh from system (root) script

Posted by redmoskito on Super User See other posts from Super User or by redmoskito
Published on 2010-06-14T17:57:19Z Indexed on 2010/06/14 18:03 UTC
Read the original article Hit count: 180

Filed under:
|
|

What's the easiest way to have a system script (running as root) execute remote commands over ssh?

I've written some scripts that execute commands remotely via ssh, and they work great when I run them as myself, as I've set up ssh-agent and keys for passwordless login. I'd like to call these when my laptop docks and undocks. I've been successful at running arbitrary scripts when docking/undocking, but since the ACPI event scripts run as root, trying to run my ssh script fails during authentication.

I tried using sudo with the -u and -i flags to simulate running the script as my user, e.g.:

sudo -u redmoskito -i /home/redmoskito/bin/remote_command

which successfully finds my private key and tries to use it, but the ssh-agent credentials are still missing, so it still needs my passphrase.

© Super User or respective owner

Related posts about linux

Related posts about ssh