0

I'm running a Raspberry that executes on the startup from the rc.local the following command:

sudo /usr/bin/python3 /home/pi/skript.py >> log.txt 2>&1 &

I need the sudo rights because the script is manipulating a lot of stuff. When the raspberry is shutdown via a button and the script, the git is called to see if there is an update:

from sh import git

git("--git dir=" self.gitDir + ".git/" ...)

The problem is, that I'm not able to submit the credentials for the remote repository hosted on Bitbucket. For the user pi I created a ~/.netrc file as mentioned here: https://confluence.atlassian.com/bitbucketserver/permanently-authenticating-with-git-repositories-776639846.html

With the user pi it' s working, but the script is run by sudo and sudo is not able to use the credentials from the home directory of pi. I did not find an option to run the git command form sh with something like -H -u pi.

Maybe there is an option to give sudo a ~/.netrc as well, but that I already tried without success. Maybe there is something special to know?

1

Anything run from rc.local will be run with root permissions so the use of sudo is redundant.

To run part of the script as another user use the su command. In particular use the form

su - pi -c "command you want to execute as the pi user"

| improve this answer | |
  • The problem is that I don't run the gitcommand out of rc.loca, I run it out of python and there it's not possible to pass su -pi -c. – turborierer Dec 5 '19 at 9:23
  • Start your Python with that invocation. – joan Dec 5 '19 at 10:14
0

I found finally a solution here https://stackoverflow.com/questions/11506124/how-to-enter-command-with-password-for-git-pull. I put the information to the .git/config file. Now sudo can access the repository also with credentials.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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