1

How do i run
ssh-add key
sudo hg clone hg@bitbucket.org/etc/etc

but use my ssh keys and not the superusers.

Hey everyone, when i use sudo with for example, sudo hg clone hg@bitbucket.org/etc/etc after i have added a key to my user account it doesnt work. I remember this is because the sudo is ran as the superuser but that user cannot have keys added to it. I remember setting some directive (im using debian) that allowed me to run that command as sudo, but still have my ssh keys taken from my normal user account but i didnt make a note of it at the time. Thanks.

Shawn
  • 313
  • 1
  • 6
  • 16
  • 1
    Why do you need to run hg under sudo? – Marcelo Cantos May 09 '10 at 22:43
  • i thought for the same reason everyone needs to run sudo, i dont want to give write permissions to my user account. I also found what i was looking for. env_keep=SSH_AUTH_SOCK added to your defaults in visudo allows sudo to use the SSH authentication from the account running sudo and also allows that cmd to use the privilege escalation. – Shawn May 09 '10 at 23:25

2 Answers2

7

The answer by Ry4an pointed me in the right direction but I found that with the current version (1.6.4) of Hg at least, you need to put --ssh (or the equivalent -e) after the hg command.

e.g.

hg clone -e 'ssh -i /path/to/key' ssh://user@host/path
Thomas Dufour
  • 1,872
  • 1
  • 16
  • 20
3

I see you found a way to have the sudo user chain off to your main user's key, but rather than using ssh-agent for something like that you're more secure explicitly specifying the key:

sudo hg --ssh '/usr/bin/ssh -i /path/to/private.key' clone hg@bitbucket.org/etc/etc 
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169