0

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.

redmoskito
  • 103
  • 4
  • possible duplicate of [SSH: execute sudo command](http://superuser.com/questions/117870/ssh-execute-sudo-command) – Sathyajith Bhat Jun 14 '10 at 18:18
  • @Sathya The user in that post is trying to execute a remote command as root on the server, whereas I'm trying to execute a remote command as root on the client. – redmoskito Jul 03 '10 at 17:32

1 Answers1

1

Nothing wrong with the sudo part. To pick up an existing ssh agent, see these answers: Sharing the same `ssh-agent` among multiple login sessions

Tobu
  • 2,663
  • 19
  • 22