Granolaboy
Granolaboy

Reputation: 333

Running ssh-agent through puppet

I am using Puppet and I want to pull Git repos through cronjobs with a specific user. I have a private key located in my ~/.ssh directory, which I add to my ssh-agent with this exec:

  exec {
  'add-ssh-key':
    cwd => '/home/user/.ssh',
    command => "bash -c 'eval $(ssh-agent) ssh-add rsa_key'",
    path => '/usr/bin:/usr/sbin:/bin:/sbin',
    provider => 'shell'
  }

According to the provision the agent was started and the identity added to the agent. However I can't pull the repo (neither can the cronjob) because I'm probably not connected to the correct ssh-agent (when pulling it asks for a password).

Is there a another way to accomplish this?

Thanks

Upvotes: 1

Views: 792

Answers (1)

Felix Frank
Felix Frank

Reputation: 8223

You can add a section to the user's ~/.ssh/config file to instruct it to use the key when connecting to the git server.

Host my-git-server
    Hostname git.example.net
    User gituser
    IdentityFile /home/user/.ssh/rsa_key

Have Puppet make sure that the private key has appropriately limited permissions.

There is no need to involve ssh-agent.

Upvotes: 2

Related Questions