Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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
share|improve this answer
This doesn't work for me. – jamjam Feb 23 '13 at 15:49
@jamjam Try sudo -E and also try some of the other solutions on the linked answer. – terdon Feb 23 '13 at 15:56

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.