7

My question is what would be a good way to run two admin accounts for developing in regards to running Homebrew, Zsh and Oh My Zsh and configuring the .zshrc file?

My reasoning for this is that I recently started a new job and would like to use my Mac with two accounts, both of which will be admins and both of which I will require devtools so as to keep my work life/dev and personal life/dev cleanly separated. I just erased my hard drive and cleanly installed OS X 10.12.3 and created two Admin accounts.

I've had a shot at setting it up however keep getting permission errors whenever I switch accounts and run terminal, usually specific to zsh completions.

My steps:

  1. Install Homebrew on both users /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
  2. Install zsh with brew brew install zsh and change to it chsh -s /bin/zsh.
  3. Install oh my zsh with curl via sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)".
  4. run sudo chown -R $(whoami):admin /usr/local.

Then I've tried a whole mess of things which I'll refrain from adding as I believe they may only lead others down a dark path.

joshuatvernon
  • 1,530
  • 2
  • 23
  • 45
  • 1. You do not need to install `ruby`. Sierra comes with it. 2. You don't need to install `zsh`. Again, Sierra comes with it. 3. `export ZSH=` before running the installation script. 4. Allow world execute for executables scripts, allow world read for readable files and allow read-execute for directories. – alvits Mar 21 '17 at 23:18

2 Answers2

4

Although this step is safe to run as root, I still recommend running the installation as non-root user to prevent catastrophic problems with root switching shell while the shell isn't working. superuser shell should never be changed.

Here's the proper way to install oh-my-zsh for multiple users.

Step 1: Ensure umask is not stricter than 022. If not set it to 022.

$ umask 022

Step 2: set and export ZSH with the destination path where the shared oh-my-zsh will be installed.

export ZSH=/usr/local/.zsh/oh-my-zsh

Step 3: Create the parent directory and make it owned by the user installing the scripts.

$ sudo mkdir /usr/local/.zsh
$ sudo chown ${USER} /usr/local/.zsh

Step 4: Run the installer.

$ bash -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Step 5: Change ownership of the installation path back to root.

$ sudo chown -R root /usr/local/.zsh

Step 6: Update location of ZSH in ${ZSH}/templates/zshrc.zsh-template

$ sudo sed -i 's|export ZSH=.*|export ZSH='${ZSH}'|' ${ZSH}/templates/zshrc.zsh-template

(Optional) Step 7: Disable auto update. This is recommended as the installation is now owned by root.

$ sudo sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/' ${ZSH}/templates/zshrc.zsh-template

From here on, each user can copy ${ZSH}/templates/zshrc.zsh-template as ~/.zshrc

alvits
  • 6,550
  • 1
  • 28
  • 28
  • When running step 6 I get the error "sed: 1: "/usr/local/.zsh/oh-my-z ...": extra characters at the end of l command". – joshuatvernon Mar 26 '17 at 05:38
  • You can ignore steps 6 and 7. Those are optional – alvits Mar 26 '17 at 05:42
  • @joshuatvernon - just skip step6. And when copying template to a user, just modify the file via `vim`. – alvits Mar 26 '17 at 05:43
  • when you say copying template to a user am I meant to have a file named `zshrc.zsh-template` instead of `.zshrc` that I'm used to? – joshuatvernon Mar 26 '17 at 06:04
  • @joshuatvernon - No. You will copy it as `~/.zshrc`. – alvits Mar 26 '17 at 06:08
  • I apolagise, I am still getting the exact same issues. May I ask which steps I have to perform on which users? It sounded like the steps only needed to be performed on one user – joshuatvernon Mar 26 '17 at 06:23
  • @joshuatvernon - `sudo` is probably overriding the value of `umask`. If this is the case, then step3 would create a very restrictive permission. Check and make sure permission of `/usr/local/.zsh` is `755`. If not `755`, then set it to `755`. – alvits Mar 26 '17 at 06:34
  • You only need to perform steps 1 to 5 once. Perform step 7 on all users. – alvits Mar 26 '17 at 06:37
  • This procedure worked for me and I am running Macos Sierra. Yours should work using this procedure too. – alvits Mar 26 '17 at 06:38
  • Since I've installed zsh via homebrew should I be using the zsh located at `/usr/local/Cellar/zsh` instead? – joshuatvernon Mar 26 '17 at 06:41
  • @joshuatvernon - You could. But if you installed it with restrictive permission you will have issue using it for another user. – alvits Mar 26 '17 at 06:43
  • I install it just doing 'brew install zsh` and it works fine on both users – joshuatvernon Mar 26 '17 at 06:44
  • It's just `oh-my-zsh` that has the auto-complete and permission issues – joshuatvernon Mar 26 '17 at 06:45
  • @joshuatvernon - then use it – alvits Mar 26 '17 at 06:45
  • Thank you for all your help. I somehow got it to work however by installing oh-my-zsh as the root user sudo sh and then again as each admin user. I'm unsure as to whether this is bad usage however it is working and giving no permissions errors or completion errors. – joshuatvernon Mar 26 '17 at 08:26
  • What is step 6 for? Replace `export ZSH=.*`with `export ZSH='${ZSH}'`? I think you need an absolute or relative path, but not `$ZSH`. – Timo Apr 02 '22 at 10:03
2

Whilst @alvits answer may have been correct I was unable to get it to work for me. I however, was able to get it to work by doing the following.

Install Homebrew (check https://brew.sh/ for up to date command):

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Zsh with Homebrew:

brew install zsh

Close terminal and reopen with ZSH as default shell:

Install Oh My Zsh as root user

sudo su

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Close terminal to exit root user mode.

Install Oh My Zsh as each admin (therefore install on both users):

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

That stopped all the auto-completions and permission errors for me. I believe this to be overkill and that there would be a way with symlinks however this way is easy.

joshuatvernon
  • 1,530
  • 2
  • 23
  • 45