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

前端 未结 13 911
小蘑菇
小蘑菇 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:31

    This problem can also occur after Ubuntu upgrades that require a reboot.

    If the file /var/run/reboot-required exists, do or schedule a restart.

    0 讨论(0)
  • 2020-12-07 20:37

    In case anyone else is stuck with this: it just means the write permissions are wrong in the repo that you’re pushing to. Go and chmod -R it so that the user you’re accessing the git server with has write access.

    http://blog.shamess.info/2011/05/06/remote-rejected-na-unpacker-error/

    It just works.

    0 讨论(0)
  • 2020-12-07 20:38

    A simpler way to do this is to add a post-receive script which runs the chmod command after every push to the 'hub' repo on the server. Add the following line to hooks/post-receive inside your git folder on the server:

    chmod -Rf u+w /path/to/git/repo/objects
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-07 20:48

    It is a permission error. The way that was most appropriate and secure for me was adding users to a supplementary group that the repo. is owned by (or vice versa):

    groupadd git
    chgrp -R git .git
    chgrp -R git ./
    usermod -G -a git $(whoami)
    
    0 讨论(0)
  • 2020-12-07 20:48

    I was getting similar error and please see below how I resolved it.

    My directory structure: /opt/git/project.git and git user is git

    $ cd /opt/git/project.git
    $ sudo chown -R git:git .
    

    chown with -R option recursively changes the ownership and and group (since i typed git:git in above command) of the current directory. chown -R is necessary since git changes many files inside your git directory when you push to the repository.

    0 讨论(0)
提交回复
热议问题