Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a secure system-wide oh-my-zsh configuration?

I'd like to have a system-wide oh-my-zsh setup, but I'm not sure what would be the "best" approach for this. It is not my intention to ask about personal preferences or the like, I'm just unsure whether the solutions below are:

  • ln my local user configuration somewhere doesn't seem right, because adding an exploit to my local cfg and therefore gain root permissions would be very easy.

  • Installing oh-my-zsh to /etc would be maybe also a security hole because I simply haven't written it by myself.

  • Simply writing my own personal .zshrc would be the last approach I would like to try out because it’s very time-consuming.

Any recommendations?

like image 220
toogley Avatar asked Jul 25 '15 08:07

toogley


People also ask

How do I set oh my zsh as my default?

Installing ZSH will not modify and set it as the default shell. We have to modify the settings to make ZSH our default shell. Use the “chsh” command with '-s' flag to switch the default shell for the user.

How do I know if oh my zsh is installed?

Most versions of macOS ship with zsh pre-installed. You can check if this is the case and if so, which version you are running using the command: zsh --version . If the version is 4.3. 9 or higher, you should be good to go (we'll need at least this version to install Oh My Zsh later on).


2 Answers

Unless I'm misunderstanding the marked answer from Caleb is just the normal per-user installation steps with adding a .zshrc file to the skel dir and changing the default new-user shell, but it doesn't actually work or really answer the question because each user still requires the oh-my-zsh dir/would still require each user to clone the oh-my-zsh dir into their own folder meaning it's not really installed system wide, it just automatically gives them a zshrc file and changes the default shell to zsh, but without oh-my-zsh in each user folder it will error out.

From what I understand of the question it's asking how to install oh-my-zsh system-wide aka have it installed in ONE place and not require manually messing around on each new user/having a git clone of oh-my-zsh on each user dir. Assuming that's the case, here's what I did based off Arch Linux's AUR Package I normally use but was looking for the same on a centos server, however this can be done on any distro. Credit goes to MarcinWieczorek and the other maintainers, I just adapted the below so can do the same on non-arch distros.

If you already have oh-my-zsh installed on root just skip to Step 3. This isn't distro specific just uses the AUR Patch File for zshrc


Step #1

Install zsh of course


Step #2

Install oh-my-zsh as root as normal (shows wget method, see Calebs answer for alternative)

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

Step #3

Move the install to /usr/share so is system-wide

#Copy zsh files to /usr/share for all uer access  mv /root/.oh-my-zsh /usr/share/oh-my-zsh # Move into the dir and copy the zshrc template to zshrc (which will be the default for users) cd /usr/share/oh-my-zsh/ cp templates/zshrc.zsh-template zshrc # Nab the patch file from MarcinWieczorek's AUR Package and apply to the zshrc file wget https://aur.archlinux.org/cgit/aur.git/plain/0001-zshrc.patch\?h\=oh-my-zsh-git -O zshrc.patch && patch -p1 < zshrc.patch 

Now oh-my-zsh is installed globally and the user just needs that zshrc file. so NOW is where Caleb's answer comes in though just do the below as /etc/adduser.conf is only on debian whereas the below should be distro independent.


Step #4

Set it up to be the default on new users

# Create hard link to the zshrc file so it creates an actual independent copy on new users sudo ln /usr/share/oh-my-zsh/zshrc /etc/skel/.zshrc # Set default shell to zsh sudo adduser -D -s /bin/zsh 

Now that's a true installation of oh-my-zsh with all new users automatically having it applied with the /usr/share/oh-my-zsh/zshrc settings and no other steps needed.

Misc Notes

  • For any pre-existing users with oh-my-zsh:

    cp /usr/share/oh-my-zsh/zshrc ~/.zshrc 
  • You can set new user OMZ defaults in /usr/share/oh-my-zsh/zshrc
  • Auto Updates are disabled since new users do not have permissions to update the /usr/share/oh-my-zsh files
    • To update oh-my-zsh just cd to /usr/share/oh-my-zsh/ and run 'sudo git pull'
  • The oh-my-zsh cache will be handled per-user within each user dir under ~/.oh-my-zsh-cache/ (automatically created)
like image 174
cFINNY Avatar answered Sep 28 '22 02:09

cFINNY


Fair Warning: this assumes a Debian style linux, but this should work on other forms as well. This also assumes you are starting from scratch.

Part 1, the install:

You will need to install zsh system wide, and not just for one user. (you may have already done this but I'll include it just to be comprehensive)

make sure you have installed zsh, simply: sudo apt-get install zsh

Follow the oh-my-zsh install guide or you can either:

use curl

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

use wget

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

Part 2, Setting up zsh when new users are added:

You will need to make it so that new users default to zsh. In your /etc/adduser.conf file edit the line that says:

DSHELL=/bin/sh 

to:

DSHELL=/bin/zsh 

You should also change it for the /etc/default/useradd file, change the line:

SHELL=/bin/sh 

to:

SHELL=/bin/zsh 

Part 3, set your custom theme.

I have a custom theme file (here) that I wanted all users on the system to have. First, you should add the file to your .oh-my-zsh/themes folder:

cp your_custom_style.zsh-theme ~/.oh-my-zsh/themes 

Next, edit your .zshrc file in your home directory, change the ZSH_THEME="default" to ZSH_THEME="your_custom_style"

Then, reload your .zshrc file with: . ~/.zshrc

Part 4, setting up new user's home directories.

We need to to place whatever files we want the new users to have in the /etc/skel directory, because this is what the system copies when it is creating new user's home directory. See this sys admin guide for details.

Copy your user's files (you may need to sudo):

cp -r .oh-my-zsh /etc/skel/ cp .zshrc /etc/skel  

Now you will be able to add new users and they will have oh-my-zsh by default with whatever custom theme you want them to have.

If you want to change all other existing user's shell to zsh, I would recommend reading this serverfault question.

like image 30
Caleb Adams Avatar answered Sep 28 '22 02:09

Caleb Adams