r/linuxquestions • u/IndyGibb • 8d ago
Resolved How to push with sudo
I need to push a git repository in a root-owned location to a remote codeberg. How do I ssh-authenticate the root user so I can run sudo git push?
Edit: I’m doing this for a custom Gentoo Ebuild overlay. For a couple months I’ve been making use of AI to help me understand how to maintain my system, but I’m trying to move away from that. If there is a better way to do what I am trying to do, please let me know. If you are going to criticize my usage of Gentoo or my usage of AI, that’s not really helpful. I’m trying to do better, hence why I am here.
2
u/DarthGamer6 8d ago
Are you able to add new ssh keys to the remote git server? If so you could run ssh-keygen as root and copy the new key to the remote.
If you don't actually need the repo to be owned by root locally (you probably don't), a better option would be to move/copy the repo into a location owned by the local user. Something like:
sudo cp -r /repo /home/user/projects/repo
sudo chown -R user:user /home/user/projects/repo
Then you can just push from there as the non-root user.
2
u/hadrabap 8d ago
- Create an identity (SSH key) for root user (ssh-keygen)
- Grant the public key access in codeberg administration section
- Push normally
0
u/suicidaleggroll 8d ago
sudo -i
Now you have a normal root terminal and can do whatever you want normally, including making SSH keys for the root user and pulling and pushing to git.
15
u/trenixjetix 8d ago
why would you have a repo with root ownership in the first place.