git: can't push (unpacker error) related to permission issues

前端 未结 13 958
小蘑菇
小蘑菇 2020-12-07 20:06

I have this problem when i try to push in git:

error: insufficient permission for adding an object to repository database ./objects

fatal: failed to write o         


        
13条回答
  •  广开言路
    2020-12-07 20:45

    For the permission error using git repository on AWS instance, I successfully solved it by creating a group, and assigning it to the repository folder recursively(-R), and give the written right to this group, and then assign the default aws instance user(ec2-user or ubuntu) to this group.

    1. Create a goup name share_group or something else

         sudo groupadd share_group
    

    2. change the repository folder from 'root' group to 'share_group'

         sudo chgrp -R share_group /path/to/your/repository
    

    3. add the write authority to share_group

         sudo chmod -R g+w /path/to/your/repository
    

    4. The last step is to assign current user--default user when login (by default ec2 is 'ec2-user', user of ubuntu instance is 'ubuntu' in ubuntu on aws) to share_group. I am using ubuntu insance on aws, so my default user is ubuntu.

         sudo usermod -a -G share_group ubuntu
    

    By the way, to see the ownership of the folder or file just type:

        ls -l  /path/to/your/repository
    

    '

    Output:

        drwxr-x--x  2 root shared_group
    
    (explanation please see:https://wiki.archlinux.org/index.php/File_permissions_and_attributes).

    After step 3, you will see

        drwx--x--x  2 root root
    

    changed to

        drwxr-x--x  2 root share_group 
    

    In this case, I did not assign user 'ubuntu' to root group, for the consideration of security. You can just try to assign you default user to root according to step 4 (just skip the first 3 steps


    In another way, tried the solution by :

        chmod -Rf u+w /path/to/git/repo/objects
    
    It did not work for me, I think it should be the reason that my repository folder belong to the root user, not to Ubuntu user, and 'git' by default use the default user(ec2-user or Ubuntu user. You can try to change the user and test it.

    Finally, below code definitely work for me, but 777 is not good for security

        sudo chmod -R 777 /path/to/your/repo
    

提交回复
热议问题