LoginSignup
15
7

More than 5 years have passed since last update.

Mac複数ユーザと"zsh compinit: insecure directories and files, run compaudit for list."

Last updated at Posted at 2018-12-13

どういうこと?

  • zshの補完初期化コマンドcompinitは、セキュリティのため補完ファイルの所有者が違うと、それをロードしてくれない。
  • Homebrewは全ユーザで共有のファイル置き場に置かれる: /usr/local
  • Macで複数ユーザを作ると、zshの補完初期化で怒られまくる

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

解決策

.zshrcに、ユーザログイン時に補完ファイルの所有権を変更する処理を書く。

.zshrc
: "Multi-user Hack" && {
    compaudit > /dev/null 2>&1 || { 
        echo "Need to change file ownership of zsh completion"
        sudo -v || exit
        compaudit 2>/dev/null | sudo xargs chown $(whoami)
    }
}

zplug

ちなみに、zplugもプラグインや補完ファイルをロードするので、所有権を変更する必要があった。

.zshrc
: "プラグイン" && {
  export ZPLUG_HOME=/usr/local/opt/zplug

  : "Multi-user Hack" && {
        [ "$(stat -f '%u' $ZPLUG_HOME/)" = "$(id -u)" ] ||  sudo chown -R $(whoami) $ZPLUG_HOME/
  }

  source $ZPLUG_HOME/init.zsh
}
15
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
7