How to generate gpg keys as sudo/root

I’m working on writing a bash script that runs in the background and executing my backup automatically using crontab.

I have everything working as it should using “pass” to place the repository passwords that are needed for kopia to connect and make the snapshots. the problem is when I try to backup i.e. /etc I have to be sudo/root and that does not work.

the reason it does not work I Have concluded is that to make a root-owned “pass - .password-store” file (where the passwords are stored in rest by “pass”) I have to have a gpg key that is linked to an email made for/by root/sudo.

I can not figure out how to do this.
I have tried these commands:

sudo gpg2 --gen-key 
sudo gpg -(k)K --full-generate-key 
sudo su --> gpg2 --gen-key 
sudo su --> gpg -(k)K --full-generate-key 

after having put in all the information required to generate said key, I just get an error message: 

    gpg: agent_genkey failed: Permission denied
    Key generation failed: Permission denied  

Can anyone help?
or how do you run automated background backups of directories that need sudo permissions?

I don’t know how you have concluded to this. I don’t use kopia. Are you really certain this is what is needed?

Create a systemd service that runs the script.

4 Likes

I don’t know how you have concluded to this. I don’t use kopia . Are you really certain this is what is needed?

Because when I run the script everything works perfectly up until it comes time to connect to the /ect repository. then I get an error saying, error connecting to the repository, no access cant find password.store which is where “pass” stores its password.

that is probably not 100% correct wording of the error I’m writing it off of memory. I will double check when I get home.

is this how professionals do it? who systems automatically allow sudo privileges?
I’m asking because I don’t know and I would like to make it/use it the right way.