Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh compinit: insecure directories and files, run compaudit for list. #433

Closed
k-lam opened this issue Jul 6, 2016 · 53 comments
Closed

zsh compinit: insecure directories and files, run compaudit for list. #433

k-lam opened this issue Jul 6, 2016 · 53 comments
Labels

Comments

@k-lam
Copy link

k-lam commented Jul 6, 2016

I use oh-my-zsh, and I has followed the document.
but when I open a new termial on my Mac,it print
Ignore insecure directories and files and continue [y] or abort compinit [n]?

@hacfi
Copy link

hacfi commented Jul 7, 2016

@k-lam Don’t have a solution but maybe a good hint: see http://stackoverflow.com/questions/13762280/zsh-compinit-insecure-directories ..you might need to change the directory ownership/rights.

@arglee
Copy link

arglee commented Jan 16, 2017

http://stackoverflow.com/a/41674919/2511142

@petemounce
Copy link

compinit -i via http://zsh.sourceforge.net/Doc/Release/Completion-System.html

@lebensterben
Copy link

lebensterben commented May 21, 2018

So here is what I did,

  1. run compaudit and it will give you a list of directories it thinks are unsecure
  2. run sudo chown -R username:root target_directory
  3. run sudo chmod -R 755 target_directory

Above is my original solution, which doesn't seem to work for some people.

Check the other solution proposed by @pine-byte
#433 (comment)

@HouCoder
Copy link

@lebensterben your solution worked for me, thanks.

@givingwu
Copy link

givingwu commented Jan 7, 2019

@lebensterben Hello, after i tried your solution, i got following error. and i don't know what happened with that? can u help me?

i ran to step 2:

sudo chown -R username:root /usr/local/share/zsh/site-functions

then the terminal outputs:

chown: root: illegal group name

i also tried google this error and tried other solutions:

  1. chown-illegal-group-name-mac-os-x
  2. zsh-compinit-insecure-directories,

but got same error too, it let me so confusing.

this is my users & groups screenshots:
image

thanks in advanced.

@ghost
Copy link

ghost commented Jan 12, 2019

@lebensterben Hello, after i tried your solution, i got following error. and i don't know what happened with that? can u help me?

i ran to step 2:

sudo chown -R username:root /usr/local/share/zsh/site-functions

then the terminal outputs:

chown: root: illegal group name

i also tried google this error and tried other solutions:

  1. chown-illegal-group-name-mac-os-x
  2. zsh-compinit-insecure-directories,

but got same error too, it let me so confusing.

this is my users & groups screenshots:
image

thanks in advanced.

@vuchan The file is a link, you must set on current dir ,and you can see your group by command id,good luck!!

@givingwu
Copy link

givingwu commented Jan 14, 2019

@mqzi thanks for your comment The file is a link, you must set on current dir, it let me know what i did error.

  1. i found the right dir at /usr/local/Homebrew/completions/zsh.
  2. i removed the group name root.
  3. i reran following shell commands:

sudo chown -R vuchan.c.wu /usr/local/Homebrew/completions/zsh
sudo chmod -R 755 /usr/local/Homebrew/completions/zsh

it works, thanks again @mqzi .

@yujiangshui
Copy link

@vuchan you save my day, thank you

@SouthRibbleTech
Copy link

if your sure the user who is logged in should have permission you could try

for f in $(compaudit);do sudo chown $(whoami):admin $f;done;

this will set the ownership correctly for every folder / file listed in the output of compaudit

@malaquiasdev
Copy link

malaquiasdev commented Mar 18, 2020

This is closed, but nothing work to me.

My machine is a MacBook Pro (15-inch, 2019) with macOS Catalina.

The solution below, works well:

$ cd /usr/local/share/
$ sudo chmod -R 755 zsh
$ sudo chown -R root:staff zsh

Sorry to comment in a closed issue.

@frab90
Copy link

frab90 commented Apr 3, 2020

if your sure the user who is logged in should have permission you could try

for f in $(compaudit);do sudo chown $(whoami):admin $f;done;
this will set the ownership correctly for every folder / file listed in the output of compaudit

this worked fine for me. it fixed 5 out fo 7 files. I fixed the other two files using

sudo chmod -R 755 target_directory

@deftdawg
Copy link

This was broken for me as well on a fresh install of Catalina with brew, I believe this should be reopened as the steps to add:

if type brew &>/dev/null; then
    FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH

    autoload -Uz compinit
    compinit
fi

to .zshrc don't mention that

for f in $(compaudit);do sudo chmod -R 755 $f;done;

needs to be run to avoid getting the error below:

zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?

@pine-byte
Copy link

just run shell follows:
compaudit | xargs chmod g-w

@ericvida
Copy link

ericvida commented May 7, 2020

SOLUTION (for me)

Reinstalling zsh via brew did it for me.
You may need to install homebrew first if you haven't already.
Start with this command.

brew install zsh

I then got an error saying brew was already installed, I just needed to link to it, and gave me this command:

brew link zsh  

I had tried to replace the links for original files, thinking it would fix my permissions error, but brew gave an error saying there's files there that need to be overwritten and told me to run this command.

brew link --overwrite zsh

After that. All my errors were gone.
I hope it helps someone out there.

@nandorojo
Copy link

just run shell follows:
compaudit | xargs chmod g-w

This worked for me on a new Mac (Catalina)

@RamirezAlex
Copy link

just run shell follows:
compaudit | xargs chmod g-w

This one worked for me 👍

@Tomotoes
Copy link

Add the following code to .zshrc or .bashrc

fixZsh() {
	for f in $(compaudit)
	do 
		sudo chown -R $(whoami):root $f
		sudo chmod -R 755 $f
	done
}

reload terminal && exec fixZsh 🙃

@xhou
Copy link

xhou commented Jul 11, 2020

just run shell follows:
compaudit | xargs chmod g-w

This one worked for me 👍

This works for me!!!

@PWrzesinski
Copy link

I just run:

sudo chmod -R 755 <dir>

for every directory listed by compaudit. Didn't need chown.

@chbrandt
Copy link

I tried to explain what is the (simple) cause for that here: https://stackoverflow.com/a/63447799/687896 , so that we don't start just typing commands we don't really understand what is going on. Basically, ZSH expects system files to be owned and modifiable (w) by either you (the one running the shell) or root.

@NanheKumar
Copy link

compaudit | xargs chmod g-w

@suejy
Copy link

suejy commented Sep 11, 2020

just run shell follows:
compaudit | xargs chmod g-w

This work for me. Thank you @pine-byte !!!

@benwoodward
Copy link

benwoodward commented Sep 19, 2020

compaudit | xargs sudo chmod g-w

I had to add sudo

@Vadorequest
Copy link

I got this error after installing Yarn or NVM on MacOS. I don't even use ZSH and I don't understand why it was installed.

I tried #433 (comment) and it didn't change anything.

@rivernews
Copy link

just run shell follows:
compaudit | xargs chmod g-w

Worked for me after a fresh macOS Big Sur install! No longer getting the warning.

@DakotaLMartinez
Copy link

So here is what I did,

  1. run compaudit and it will give you a list of directories it thinks are unsecure
  2. run sudo chown -R username:root target_directory
  3. run sudo chmod -R 755 target_directory

I got the same error as @givingwu. (illegal group name) But just running the chmod command in step 3 on each directory worked for me to enable the autocomplete. (on Mac OS 10.15.6)

@e0da
Copy link

e0da commented Dec 19, 2020

I hope folks read the thread a bit before recursively and unnecessarily chmodding a bunch of random stuff with +x. You really just want to remove group write permission, which is the compaudit | xargs chmod g-w solution several have suggested.

Not that there's a big scary downside or anything. But insofar as the files have "correct" permissions, not everything is "supposed" to have the executable bit set. Probably harmless in most/all situations, but if you're trying to understand and fix the problem, it's that the indicated files have the group writable bit set, and that's the thing you're changing with chmod 755, and that thing is more precisely fixed with chmod g-w. ❤️ 🌈 🖖

200

Edited 1 Jan 2021: Wait, no. I misread that. Never mind.

@airtonix
Copy link

airtonix commented Jan 5, 2021

just run shell follows:
compaudit | xargs chmod g-w

Does nothing:

~/Projects/**** master                                                                                                                                  ? 1|0|0 Node system @####
? compaudit                  
There are insecure files:
/usr/local/share/zsh/site-functions/_brew
/usr/local/share/zsh/site-functions/_brew_cask

~/Projects/**** master                                                                                                                                  ? 1|0|0 Node system @####
? ls -al /usr/local/share/zsh/site-functions/     
total 0
drwxr-xr-x  5 zeno.jiricek  admin  160 Apr  2  2019 .
drwxr-xr-x  3 zeno.jiricek  admin   96 Mar  5  2018 ..
lrwxr-xr-x  1 zeno.jiricek  admin   39 Mar  5  2018 _brew -> ../../../Homebrew/completions/zsh/_brew
lrwxr-xr-x  1 zeno.jiricek  admin   44 Mar  5  2018 _brew_cask -> ../../../Homebrew/completions/zsh/_brew_cask
lrwxr-xr-x  1 zeno.jiricek  admin   58 May 17  2018 spaceship.zsh -> /usr/local/lib/node_modules/spaceship-prompt/spaceship.zsh

~/Projects/**** master                                                                                                                                  ? 1|0|0 Node system @####
? compaudit | xargs chmod g-w                
There are insecure files:

~/Projects/**** master                                                                                                                                  ? 1|0|0 Node system @####
? ls -al /usr/local/share/zsh/site-functions/
total 0
drwxr-xr-x  5 zeno.jiricek  admin  160 Apr  2  2019 .
drwxr-xr-x  3 zeno.jiricek  admin   96 Mar  5  2018 ..
lrwxr-xr-x  1 zeno.jiricek  admin   39 Mar  5  2018 _brew -> ../../../Homebrew/completions/zsh/_brew
lrwxr-xr-x  1 zeno.jiricek  admin   44 Mar  5  2018 _brew_cask -> ../../../Homebrew/completions/zsh/_brew_cask
lrwxr-xr-x  1 zeno.jiricek  admin   58 May 17  2018 spaceship.zsh -> /usr/local/lib/node_modules/spaceship-prompt/spaceship.zsh


~/Projects/**** master                                                                                                                                  ? 1|0|0 Node system @####
? compaudit
There are insecure files:
/usr/local/share/zsh/site-functions/_brew
/usr/local/share/zsh/site-functions/_brew_cask

:D

@veljkho
Copy link

veljkho commented Jan 11, 2021

@lebensterben Hello, after i tried your solution, i got following error. and i don't know what happened with that? can u help me?

i ran to step 2:

sudo chown -R username:root /usr/local/share/zsh/site-functions

then the terminal outputs:

chown: root: illegal group name

i also tried google this error and tried other solutions:

  1. chown-illegal-group-name-mac-os-x
  2. zsh-compinit-insecure-directories,

but got same error too, it let me so confusing.

this is my users & groups screenshots:
image

thanks in advanced.

Where it says username:root just place your username so it looks like:
sudo chown -R YOUR_USERNAME_ONLY /usr/local/share/zsh/site-functions
then run sudo chmod -R 755 usr/local/share/zsh/site-functions

Then if you have more insecure directories do the same, like in my case this folder only usr/local/share/zsh

@tyirvine
Copy link

tyirvine commented Feb 7, 2021

So here is what I did,

  1. run compaudit and it will give you a list of directories it thinks are unsecure
  2. run sudo chown -R username:root target_directory
  3. run sudo chmod -R 755 target_directory

Above is my original solution, which doesn't seem to work for some people.

Check the other solution proposed by @pine-byte
#433 (comment)

Thank you for this solution. I'd just like to add, if you have admin privileges you shouldn't have to use sudo.

As well, only the top level directory needs to be secured. So for example if the directories that are insecure are ⤵︎

/usr/local/share/zsh/site-functions
/usr/local/share/zsh

then you only have to secure /usr/local/share/zsh.

For anyone wondering, 755 is a flag for chmod that does the following ⤵︎

Screen Shot 2021-02-07 at 10 48 17 AM

@AkylaiSh
Copy link

just run shell follows:
compaudit | xargs chmod g-w

that worked for me as well, thank you

@truonglx-dev
Copy link

@mqzi thanks for your comment The file is a link, you must set on current dir, it let me know what i did error.

  1. i found the right dir at /usr/local/Homebrew/completions/zsh.
  2. i removed the group name root.
  3. i reran following shell commands:

sudo chown -R vuchan.c.wu /usr/local/Homebrew/completions/zsh
sudo chmod -R 755 /usr/local/Homebrew/completions/zsh

it works, thanks again @mqzi .

work for me
many thanks

@giorgiovinci
Copy link

So here is what I did,

  1. run compaudit and it will give you a list of directories it thinks are unsecure
  2. run sudo chown -R username:root target_directory
  3. run sudo chmod -R 755 target_directory

Above is my original solution, which doesn't seem to work for some people.

Check the other solution proposed by @pine-byte
#433 (comment)

sudo chmod -R 755 on the offending folder was enough for me!

@strafe
Copy link

strafe commented Mar 3, 2021

Just so people know, the magical chmod g-w is removing write permissions for the group. It would seem zsh does not like anyone but you having write access to these folders.

@brunomrlima
Copy link

If you are installing Heroku with Homebrew, please check this docummentation: https://docs.brew.sh/Shell-Completion

Additionally, if you receive “zsh compinit: insecure directories” warnings when attempting to load these completions, you may need to run this:"

 chmod -R go-w "$(brew --prefix)/share"

@yudshj
Copy link

yudshj commented Mar 26, 2021

just run shell follows:
compaudit | xargs chmod g-w

Works for me (Catalina with Homebrew 2.7.5). Thanks a lot.

@gniw
Copy link

gniw commented Apr 2, 2021

just run shell follows:
compaudit | xargs chmod g-w

Works for me! Thanks!

@millisami
Copy link

I'm on bigsur and this #433 (comment) worked for me.

@troyfontaine
Copy link

troyfontaine commented Apr 8, 2021

On macOS Catalina, the below worked for me as compaudit | xargs chmod g-w and #433 (comment) did not due to the way Homebrew is installed on my system.

  1. run compaudit for the list of insecure directories
  2. run sudo chown -R ${WHOAMI}:staff target_directory
  3. run sudo chmod -R 755 target_directory

@DavidUps
Copy link

Run

  1. sudo chmod -R 755 /usr/local/share/zsh
  2. sudo chown -R root:staff /usr/local/share/zsh

@TeemuSuoranta
Copy link

Use compaudit to see paths to insecure directories/files. Notice that if the insecure file is symlink, just chmod/chown the symlink is not enough and you need to check the target of symlink and chmod/chown that too. To see symlink targets I used just ls -la /usr/local/share/zsh/site-functions.

@u-ways
Copy link

u-ways commented Aug 3, 2021

My problem was my export ZSH="home/{WRONG_USER}/.oh-my-zsh" had the wrong user because my .zshrc was an import from another machine. I change it to export ZSH="$HOME/.oh-my-zsh" and this solved it for me.

@maybeageek
Copy link

This is still not solved!

I make it a habit to NOT work with a user with admin rights. If I change the rights for the compaudit to be clear, I can't update or use homebrew anymore. It will outright reject doing anything.
So I had to revert the changes, giving me the "compinit: insecure directories" every time I open the terminal.

What can I do with a admin user and a non-admin user to not get this output on either users?

@edmund-oconnell
Copy link

edmund-oconnell commented Sep 21, 2021

Executing
compaudit | xargs chmod g-w
for me simply outputs ➜ ~ compaudit | xargs chmod g-w There are insecure directories and files:

with an empty list.

@jakubprogramming
Copy link

All of the proposed solutions did not work for me. What I finally did is uninstalling brew by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
This will download and execute the uninstall script.
Finally installing brew again (if needed) will be possible.

@dijonkitchen
Copy link

All of the proposed solutions did not work for me. What I finally did is uninstalling brew by running: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)" This will download and execute the uninstall script. Finally installing brew again (if needed) will be possible.

Just reinstall brew with the script on their site works for me on the current user.

In my situation, I've got multiple users on one laptop with one of them having installed brew. When the other references and uses brew autocompletions on login, I get zsh's insecure directories message. Seems like all users are in the proper groups and there are no write permissions for those groups, so not sure what the problem is. I don't want to change the owners of the files since I want both users to be able to utilize brew autocompletions.

@msva
Copy link
Contributor

msva commented Nov 7, 2021

then just make sure users are not going to do businness with files that belongs to another user

@mateofumis
Copy link

mateofumis commented Jan 23, 2022

Works for me run the follow commands:

compaudit 
sudo chown -R root:root target_directory
sudo chmod -R 755 target_directory

"compaudit" for the list of insecure (target_directory)
.
.
Thanks you!

@nhooyr
Copy link

nhooyr commented May 25, 2022

You want to use:

compinit -u

To disable the annoying permissions test. It doesn't add any security on macOS. See the documentation at zshcompsys(1).

@mateofumis
Copy link

Yessss, it's the correct way. Thanks you bro!

@zsh-users zsh-users locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests