Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I created a script that runs duplicity to backup files I have on a VPS,and uses a GPG key that I generated as a user.

When I try and run this script as SUDO I get:

GPGError: GPG Failed, see log below:
===== Begin GnuPG log =====
gpg: C7B2Y6DO: skipped: public key not found
gpg: [stdin]: encryption failed: public key not found ===== End GnuPG log =====

Now I realize why this is (because it's not SUDO's key, it's the users key) but before I go and re-generate a key for SUDO is it possible to have sudo use the users key?

Not really important but the script is modeled off a combination of these three sites: http://www.cenolan.com/2008/12/how-to-incremental-daily-backups-amazon-s3-duplicity/

http://www.randys.org/2007/11/16/how-to-automated-backups-to-amazon-s-s3-with-duplicity/

https://help.ubuntu.com/community/DuplicityBackupHowto

share|improve this question
    
there is no such entity as SUDO. there is a command 'sudo' that lets you run commands as root or another user. –  Justin Feb 7 '10 at 21:06

4 Answers 4

Have you tried the --homedir option?

share|improve this answer
    
There is no --homedir option for duplicity, or atleast it's not working: Command line error: option --homedir not recognized –  BassKozz Feb 7 '10 at 3:52
2  
@BassKozz: You would use duplicity's --gpg-options option to pass the --homedir option to gpg: duplicity ... --gpg-options "homedir=/home/username/.gnupg" ... (untested) –  Dennis Williamson Feb 7 '10 at 7:48
up vote 2 down vote accepted

Solution: Added the following to the bash script:

HOME=/home/user/

Fin

share|improve this answer

are you sure you mean to be encrypting your backups with a users gpg key in the first place?

unless you have a separate backup of your gpg key(which I hope you do) you will be unable to decrypt any of the backups if you lost the contents of your home directory.

share|improve this answer

I believe the default configuration of sudo is to preserve $HOME. So if you were logged in as user1, and used sudo scriptname where scriptname did echo $HOME, you should expect to see "/home/user1" echoed back, not "/root".

I'll assume BassKozz hasn't changed this. Perhaps he's not logged in as his desired user1, running the script as sudo. Perhaps he's really just running the script as root, for example through root's cronjob. In that case, his $HOME would never have been /home/user1 in the first place, so even if sudo preserves the value of $HOME it's not helping. In this case, any of the other answers that tell you how to set $HOME to the right value, or to inform gpg where your homedir is, should work.

If however, it's true as he says that he can't even run his duplicity script "as sudo"---that is, when logged in as user1 and typing sudo duplicity_script, then the problem is not going to be a wrongly-set $HOME. As we've seen, $HOME should in that case have the right value. So the problem is something else. I haven't heard enough, and don't know duplicity+gpg well enough, to speculate what it might be.

share|improve this answer

Your Answer

 
discard

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.