Error unable to unlink old permission denied

TL;DR -- check file permissions; on Linux?--maybe don't use Sudo with Git! This error is almost definitely a permissions issue. In my case, outlined herein, the problem stemmed from a blatant abuse of sudo. Let's break it all down.

A branch management error that can seemingly come out of nowhere. Don’t worry, there’s an easy fix for this one. The key may be in understanding the real power of Sudo in Linux.

TL;DR — check file permissions; on Linux?—maybe don’t use Sudo with Git!

This error is almost definitely a permissions issue. In my case, outlined herein, the problem stemmed from a blatant abuse of sudo. Let’s break it all down.

On certain occasions, it can be a strong temptation to use Sudo as a fix-for-all. In the normal process of development, Git can occasionally get hung up for reasons not outwardly evident; sometimes, rather than actually take the time to understand the complexities of Git, it’s easier to just force your way through it. Sudo, at it’s face, would seem like just another tool for coercing Git into compliance with your busy workflow. If you’ve been on the Linux command-line for any amount of time, you’ll know that Sudo is a valuable tool for ‘forcing’ certain tasks. In the case of Git, however, it’s anything but that. Here’s why…

Sudo at a Glance

From the get go, you need to understand that Linux systems limit the power of users by default. There’s your user profile, and then there’s the ROOT profile. This may not be a semantically accurate description of ROOT, but you can think of ROOT as a «super user» on your computer: a user profile that has access to anything and everything. With that said, there will be times when you need to assume the role of this super user—i.e., your user profile simply doesn’t have the permissions necessary to get something done. Here’s a classic example: there’s a file you’d like to edit, but you don’t have write access on the file (you open the file in an editor, but it doesn’t want to save). Changing file permissions aside, if you’d like to overcome this, the easiest way to get past this is to use Sudo. 

An important note: on any Linux system, there will be files that belong to you (usually located within your user folder just below /home), and there will be files that belong to ROOT (often above the ~/user folder).

Why not Sudo with Git?

We’ll take a look at what happens, but let’s start with how you might find yourself wanting to use Sudo with Git.

I don’t recall the exact cause, but I do recall that one day I was trying to check out a local branch on my local machine: I think I was looking to get back onto Master (now known outside Acquia hosting as Main) from some branch I was fooling around with. When I ran git checkout master, Git gave me some business about not having the permissions necessary to unlink files. I thought to myself, «wierd!?» and proceeded to stare at my terminal just long enough to loosely connect these permission problems with past use of Sudo completely unrelated to web work. «Could it be that my user profile somehow has lost permission to use Git?»—I pondered.

Being in the hurry that I always am, I didn’t take much time to read the actual output staring me in the face on my terminal. I said to myself, «let’s try Sudo» and see if that works: sudo git checkout master. Sure enough, I find myself on master, and I get on with my day: «sharks don’t look back because they have no necks; necks are for sheep!»

I felt somewhat accomplished for all of a few days, when suddenly the problem showed up again. And then it showed up again, and again, and again—to the point that I was suddenly using Sudo for just about everything I did with Git. Here’s a look at a more recent incident—going to pull a branch of Drupal module updates from remote, I hit the same problem:

a permission error on the git command line

Git… why hast though forsaken me?

I’m sick and tired of this… let’s figure this out.

A GitKraken permissions error

If you’re using GitKraken for workflow management, you’ll get a similar error to what you see on the command-line. Arguably, «could not open ‘/pathto/file’ for writing: Permission denied» is a bit more descriptive. Good on GitKraken! I don’t use this application as much as I should!

Unlink in this case means overwrite/delete. The permission denied comment is attached to each individual file. What if I was tremendously wrong? What if this has nothing to do with my user profile having permission to use Git? What if, like the output suggests, it has everything to do with file permissions? AHA!

As with just about every other problem I’ve ever had, there’s a StackOverflow thread dealing with this. What’s the consensus there?—Git can’t overwrite the local files with whatever is coming in from remote because my user profile doesn’t own the files in question. Why wouldn’t I own the files in question? After all, the entire codebase resides under /home/terracoders/Sites. This is what happens when you use Sudo in git; per this little gem of an answer at AskUbuntu, you change the owner of whatever files you’re working with to ROOT.

Let’s go cd into the google_tag folder and see what’s going on:

show the permissions on the contents of the google tag folder

… and… there you have it!

Engage British accent: «What have you done!?»

Yeah. I’ll admit it. I was a dunce to use Sudo in the first place—it was a knee jerk reaction to a problem I didn’t have time to think through. But, as with all of my mistakes, I generally take a step back and remind myself it’s all part of the process. Sometimes you just have to screw it all up before you can grow as a developer. Once you remember what Sudo is actually used for, it makes perfect sense. I also gain a little solace in the fact that I’m not the only one out there to have made this mistake.

What we need here is to get the correct ownership on these files and folders. As a one off fix for this specific pull, I can cd into the parent directory for the google_tag folder and recursively change the ownership. Ironically, I’ll have to use Sudo to do it. It will look something like this:

use c-h-own to recursively give a folder the correct owner

Problem solved!

After this quick ownership change, sure enough I was able to pull down that branch from remote. Go figure. If you’ve screwed up various files and directories the way I have, you may need to change permissions/ownership on your Drupal root (recursively—i.e., $ sudo chown -R user:group /path/to/drupal/root).

We’re beginning to scratch the surface of a much larger issue: who exactly should site files belong to? Git obviously has problems when they belong to root, but the answer here isn’t exactly cut and dry. It can depend on quite a lot of factors: i.e., where the docroot is located, whether you’re running a traditional LAMP stack, whether you’re running MAMP, and whether or not you’re using middle-men like Drush to manage your site. You’ll want to be sure to reference the documentation for your specific application.

Вопрос:

На удаленном сервере у меня установлен пост-прием, чтобы сделать git checkout моего репозитория:

#!/bin/sh
GIT_WORK_TREE=/var/www/<website> git checkout -f

Но когда я нажимаю локальную машину на репозиторий git на сервере, я получаю следующие сообщения об ошибках:

remote: error: unable to unlink old '<file>' (Permission denied)

Это появляется много раз, одно сообщение об ошибке почти для каждого файла.

Однако у меня есть файл README.txt, который я могу изменить с помощью git, вот его разрешения:

-rw-r--r--  1 <serverusername>  <serverusername>  2939 Aug  2 10:58 README.txt

Но другие файлы с одинаковым владельцем и теми же разрешениями дают мне эту ошибку.

В другом локальном репозитории для другого веб-сайта у меня есть файлы с именем пользователя локальной машины в качестве владельца, а когда я нажимаю на удаленный сервер, он уважает владельца удаленных серверов и работает как шарм.

Очевидно, что это ошибка, связанная с разрешениями, но я не могу найти способ ее исправить, любые предложения?

Лучший ответ:

Если вам нужно отключить файл, вы должны иметь разрешение “w” для каталога, в котором находится файл, а не для файла…

Ответ №1

sudo chmod -R ug+w .;

Эта команда исправит проблему. Это дает права на запись в папку.

Ответ №2

Если вы используете какую-либо IDE, скорее всего, проблема в том, что файл использовался каким-то процессом. Как и ваш tomcat, вы можете использовать файл. Попытайтесь определить этот конкретный процесс и закрыть его. Это должно решить вашу проблему.

Ответ №3

У меня была та же самая проблема, и ни одно из вышеупомянутых решений не работало для меня. Я удалил оскорбительную папку. Затем:

git reset --hard

Удалил все устаревшие файлы, чтобы очистить состояние git, затем сделал:

git pull

Наконец-то это сработало.

ПРИМЕЧАНИЕ. Если папка была, например, общедоступной папкой с файлами сборки, не забудьте перестроить файлы

Ответ №4

FWIW – У меня была аналогичная проблема, и я не уверен, что это облегчило ее (за пределами разрешающего мода): Закрытие Eclipse, использующее ветвь с этой проблемой.

Ответ №5

Это старый вопрос, но это может помочь пользователям Mac.

Если вы копируете файлы из Time Machine вручную, а не восстанавливаете их через Time Machine, он добавит ACLs ко всему, что может испортить ваши права.

Например, раздел в этой статье, в котором говорится, что “Как исправить права на файлы Mac OS X” показывает, что “каждый” имеет пользовательский интерфейс разрешений, которые все испортили:

Плохие разрешения, от http://dreamlight.com/how-to-fix-mac-разрешения -os-х файл

Вам нужно удалить ACL из этих каталогов/файлов. Этот ответ Суперпользователя входит в него, но вот команда:

sudo chmod -RN .

Затем вы можете убедиться, что ваши каталоги и файлы имеют соответствующие разрешения. Я использую 750 для каталогов и 644 для файлов.

Ответ №6

Я получаю эту ошибку и другие странные ошибки git, когда у меня работает сервер (в Intellij). Остановка сервера и повторная попытка команды git часто фиксируют его для меня.

Ответ №7

git reset --hard

Работал для меня

Ответ №8

Я думаю, что проблема может быть связана с правами собственности на папку, поэтому установите ее для текущего пользователя.

sudo chown -R your_login_name /path/to/folder

Вы можете найти решение [здесь] [1]

Ответ №9

Некоторые файлы защищены от записи, что даже Git не может перезаписать его. Измените разрешение папки, чтобы разрешить запись, например, sudo chmod 775 foldername

А потом мерзавец тянуть снова

Ответ №10

Также не забудьте проверить разрешение самого корневого каталога!

Вы можете найти:

drwxr-xr-x  9 not-you www-data  4096 Aug  8 16:36 ./
-rw-r--r--  1     you www-data  3012 Aug  8 16:36 README.txt
-rw-r--r--  1     you www-data  3012 Aug  8 16:36 UPDATE.txt

и появится сообщение об ошибке “denied”.

Ответ №11

Потянув, возможно, создал локальные изменения.

Добавьте свой неотслеживаемый файл:

мерзавец добавить.

Копить изменения.

мерзавец

Отбросьте локальные изменения.

Git Stash Drop

Потяните с разрешением sudo

sudo git pull удаленная ветка

#git #ubuntu

Вопрос:

Запустив git stash под моим сервером ubuntu, я получил ошибки :

 ubuntu@ip-NN-NN-NN-NN : AWS Ubuntu Server :/var/www/html/tads$ git stash 
Saved working directory and index state WIP on master: 5cf9b22 Setting email gun
error: unable to unlink old '.editorconfig': Permission denied
error: unable to unlink old '.env.example': Permission denied
error: unable to unlink old '.gitattributes': Permission denied
error: unable to unlink old '.gitignore': Permission denied
error: unable to unlink old '.styleci.yml': Permission denied
error: unable to unlink old '1.blade.php': Permission denied
error: unable to unlink old '1.js': Permission denied
error: unable to unlink old '1.php': Permission denied
error: unable to unlink old '1.txt': Permission denied
error: unable to unlink old 'README.md': Permission denied
error: unable to unlink old '': Permission denied
error: unable to unlink old 'artisan': Permission denied
error: unable to unlink old 'c': Permission denied
error: unable to unlink old 'codepen.blade.php': Permission denied
error: unable to unlink old 'composer.json': Permission denied
error: unable to unlink old 'composer.lock': Permission denied
error: unable to unlink old 'invalid.html': Permission denied
error: unable to unlink old 'package.json': Permission denied
error: unable to unlink old 'php': Permission denied
error: unable to unlink old 'phpunit.xml': Permission denied
error: unable to unlink old 'route_list.txt': Permission denied
error: unable to unlink old 'server.php': Permission denied
error: unable to unlink old 'tailwind.config.js': Permission denied
error: unable to unlink old 'valid.html': Permission denied
error: unable to unlink old 'webpack.mix.js': Permission denied
fatal: Could not reset index file to revision 'HEAD'.
ubuntu@ip-NN-NN-NN-NN : AWS Ubuntu Server :/var/www/html/tads$ cd ../
ubuntu@ip-NN-NN-NN-NN : AWS Ubuntu Server :/var/www/html$ ls -la
total 28
drwxrwxrwx  3 root root    4096 Jul 28 11:31 .
drwxr-xr-x  3 root root    4096 Jul 28 11:21 ..
-rwxrwxrwx  1 root root   10918 Jul 28 11:21 index.html
-rwxrwxrwx  1 root root    3068 Jul 28 11:31 info.php
drwxr-xr-x 16  755 ubuntu  4096 Jul 28 14:42 tads
 

Я не уверен, но похоже, что это произошло после прочтения некоторых руководств, в которых я
пытался предоставить разрешения на выполнение пользователю ubuntu, под которым я вошел в консоль своего сервера:

 sudo chown -R ubuntu:ubuntu .
sudo chown 755 .
ls -la
...
drwxr-xr-x 16    755 ubuntu   4096 Jul 28 14:42  . 
 

Была ли в этом причина и как это можно исправить?

Спасибо!

Ответ №1:

Учитывая /var/www/html , что папка и файлы принадлежат root, неудивительно, что любая команда, выполняемая как ubuntu, завершится ошибкой.

Попробуйте хотя бы чаун (который вы сделали в разделе « . , но я не знаю, была ли ваша текущая папка /var/www/html ):

 cd /var/www/html
sudo chown -R ubuntu:ubuntu .
 

Затем проверьте владельца и повторите свою git команду.

Проверьте также:

  • ваши переменные среды для любых переменных GIT_xxx
  • ваши псевдонимы в случае git , если сам псевдоним
  • which git в случае git , если обернут пользовательским сценарием
  • /var/www/html/tags/.git , чтобы убедиться, что хранилище находится непосредственно под tads .

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error unable to request shsh что это 3utools
  • Error sparse file not allowed ubuntu
  • Error unable to read askpass response from
  • Error source net sqlclient data provider
  • Error unable to perform an operation on node rabbitmq

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии