git init shows 'error: chmod ... .git/config.lock failed: Operation not permitted'

14,491

Solution 1

As per this answer, sudo git ... (or running git from root equivalently) might help -- it helped me.

It's kind of silly that chmod fails for normal users but not for root, even though the underlying problem is that NTFS does not support Unix permissions. Changing the mount options is nice when you have the luxury to.

Also, edit .git/config and set filemode = false, if not already so. git config core.fileMode false also does this, but runs into the same lockfile permission problem.

Answering just because this is the first entry in search result for ".git/config.lock failed: Operation not permitted"

Solution 2

As explained here in Mount Options table, you can mount ntfs-3g in several ways.

If you are mounting it like below, the permissions are determined by the mount options, not by the file metadata (ACL). So chmod won't be able to change permissions, and it fails with an error.

MODE: Same ownership (uid, gid) and permissions for all files and directories (restricted by fmask, dmask and umask)
WHEN: uid or gid or fmask or dmask or umask defined, and no user mapping file found

So, to make sure chmod won't fail, just don't specify any of these (uid, gid, fmask, dmask or umask) in the mount options. You have some alternatives depending on if you want to deal with permissions like Windows does or just ignore permissions completely from Linux.

Mount it like below if you want to just ignore all access control (chmod, chown and permission checks won't do anything or return any errors). This is the simplest way:

MODE: No permission checks
WHEN: No uid, gid, fmask, dmask, umask, permissions or acl option, and no user mapping file found

If you want to enable access control with some compatibility with Windows, you could just use permissions mount option (and none of those others mentioned before).
However, this restricts access to private folders like C:\Users\<You>, so you would probably have to specify a user mapping file (C:\.NTFS-3G\UserMapping) anyways, to map your Windows user SID to your Linux user UID. This is more complex, so I recommend to just ignore permissions if you can do that.

MODE: Standard permission checks, according to ownership and mode, but POSIX ACLs not used (uid, gid, fmask, dmask and umask ignored)
WHEN: No uid, gid, fmask, dmask, or umask, or acl defined, but permissions defined, and no user mapping file found
OR WHEN: [...] user mapping file found

Example fstab entry (the relevant implied silent option is effective since I don't specify the others):

UUID=0123456789ABCDEF /windows ntfs noatime,users,windows_names
Share:
14,491

Related videos on Youtube

TheSmokingGnu
Author by

TheSmokingGnu

Updated on September 18, 2022

Comments

  • TheSmokingGnu
    TheSmokingGnu over 1 year

    File rights is the worst thing for me in Ubuntu. This time i get this problem:

    enter image description here

    So, background info :

    It is ntfs partition;

    I have already run sudo chown *username*:*username* -R partition_mount_point;

    I am able to create/delete directories there without sudo;

    No error messages on running git init on the linux filesystem;

    EDIT: I need to be able to work with the files from Windows