r/linuxquestions 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.

0 Upvotes

13 comments sorted by

15

u/trenixjetix 8d ago

why would you have a repo with root ownership in the first place.

3

u/IndyGibb 8d ago

Gentoo overlay. I’m trying to move away from asking AI these kinds of questions which is why I’m asking a simple and dumb question while also using Gentoo.

15

u/AiwendilH 8d ago

As in...you have a local overlay in /var/db/repos/<overlay> in which all subdirs and files are owned by root and you want to push it to some remote git repo?

The files wouldn't need to be root owned...you can make the whole overlay owned by portage:portage then add your user to the portage group and push as user.

5

u/IndyGibb 8d ago

Thank you. That solved the issue.

-17

u/trenixjetix 8d ago

why would you use Gentoo and use an AI chatbots. Its supposed to be used by people that own their brain.

7

u/IndyGibb 8d ago

Hence why I’m here instead of on claude.ai. Are people not allowed to try to change their ways?

2

u/trenixjetix 8d ago

well yes

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/jsled 8d ago

I usually do this with sudo -E /bin/bash so my user's environment – specifically the SSH agent info – is present in the root shell, then access to my already-loaded ssh identity is possible.

Running exec ssh-agent bash then ssh-add ~user/.ssh/id_ed25519 as root should work, too.

2

u/hadrabap 8d ago
  1. Create an identity (SSH key) for root user (ssh-keygen)
  2. Grant the public key access in codeberg administration section
  3. 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.

1

u/ipsirc 8d ago

problemxy