Use sudo inconjunction with regular user's ssh key

1

I want to execute a command which requires root privileges so I use sudo.

sudo puppet apply /etc/puppet/manifests/site.pp

This command involves cloning a private github repo with ssh. The only way this works is if I add my ssh to the root user.

I don't want to add my ssh to root user. How can I use sudo but still use the ssh key for the ubuntu user?

jamjam

Posted 2013-02-23T14:35:31.840

Reputation: 111

Answers

0

I found this answer over on Server Fault. Essentially, you need to add this line to /etc/sudoers (use visudo):

Defaults    env_keep+=SSH_AUTH_SOCK

You should then be able to runt your command normally:

sudo puppet apply /etc/puppet/manifests/site.pp

terdon

Posted 2013-02-23T14:35:31.840

Reputation: 45 216

This doesn't work for me. – jamjam – 2013-02-23T15:49:35.913

@jamjam Try sudo -E and also try some of the other solutions on the linked answer. – terdon – 2013-02-23T15:56:06.150

0

It turn's out there was a pretty simple solution to this.

Adding a -u option allows me to specify a user.

sudo -u ubuntu puppet apply /etc/puppet/manifests/site.pp

Now the ssh key for that user will be used.

jamjam

Posted 2013-02-23T14:35:31.840

Reputation: 111