36

I have installed zsh and I am using Oh My ZSH plugins. Everything works fine, but when I become a root user, it changes to the default zsh theme.

What should I do to make the Oh My ZSH configuration as the default zsh for all users including root?

I have tried using the chsh -s /bin/zsh root

That gave me zsh but not oh_my_zsh

I also tried cp -R /home/user/.zshrc /root/.zshrcing to get oh_my_zsh for root, but nothing worked.

(I don't need zsh but I need oh_my_zsh for all the user in the system)

3
  • How are you becoming root?
    – frlan
    Sep 8, 2014 at 12:01
  • 1
    How did you install oh my zsh in the first place? Any why not just do the same for root?
    – Adaephon
    Sep 8, 2014 at 12:26
  • 1
    I think cFINNY's answer on stackoverflow.com/a/42193058/1408600 is what you need. I've done that for months on servers i managed. It works for root and all users
    – ayik
    Jan 2, 2019 at 2:57

9 Answers 9

35

I made symbolic links to my zsh files in my home dir, that seems to work fine:

ln -s $HOME/.oh-my-zsh           /root/.oh-my-zsh
ln -s $HOME/.zshrc               /root/.zshrc

Disclaimer (Updated 2020-3-9): Only do this on a single user machine as it will make a user able to run programs as root (see comment by Eliah Kagan).

10
  • 2
    This should be the accepted answer, eliminates the hustle of installing zsh twice. Aug 17, 2016 at 10:11
  • 2
    If you do that, it actually doesn't make sense to link .oh-my-zsh, because the .zshrc still references the .oh-my-zsh of your original user. Mar 3, 2017 at 8:14
  • 1
    Didn't work for me when trying to link from non-root to root, ended up installing it for the non-root as well Apr 7, 2017 at 13:55
  • 3
    I tried it and could not use oh-my-zsh plugins using this method. They were considered insecure by compinit.
    – Melebius
    Jul 18, 2017 at 8:48
  • 17
    I recommend against this method, at least if one does not first consider the security risks. Any program the user runs can edit those configuration files without prompting the user--because they belong to the user, not root--and thus can cause root to perform any action whatsoever next time root uses zsh! Would you be willing to add (or okay with someone else adding) a warning about that to this answer? Jul 30, 2017 at 20:29
13

Just run the install command as root user (after doing sudo su)

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

For anyone else with the same question, I would recommend a combination of Tummala Dhanvi's and Morton's approach. I installed oh-my-zsh both as root and as the user using the following commands:

User:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Root:

su
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Then I created a symbolic link for the config file (run as user):

sudo ln -s /root/.zshrc $HOME/.zshrc

Make sure the user has permissions to read the file:

sudo chmod 744 /root/.zshrc

This approach allows for a shared config while keeping the system secure. You will, however, need root privileges to edit .zshrc

2

First install zsh or some shell with say oh-my-zsh as a normal user.

If you have normally setup the zsh shell & oh-my-zhs framework, then don't just sudo su into root & type chsh -s $(which zsh) $(whoami) to change shell & framework

First create system links in root of your home shell & framework configs;

  • ln -s $HOME/.zshrc /root/.zshrc
  • ln -s $HOME/.oh-my-zsh /root/.oh-my-zsh

Then after that go on and change the shell chsh -s $(which zsh) $(whoami)

BUT if you already changed the shell before making the system links then you will get a return of probably /root/.zshrc or so file already exists.

There you have to navigate to the source /root & delete whatever existing file they said & then do the system link command required to create it again but sourced from home.

After that you will have a root with the same shell & framework like you have in your normal user's terminal

if you have already done all these & it doesn't work because of permission issues, then just grant the permission to these root files;

  • sudo chmod 744 /root/.zshrc
1

I installed oh-my-zsh with root account. Now I login with another account, and install oh-my-zsh again in the home directory of the account. It works for the non-root account.

2
  • 1
    It doesn't work for me - it tells me that it's already installed in root account (where I initially installed it), and that I need to reinstall it. I suppose that the symbolic link method is the way to go for me. I don't know if it changed since the time of your answer. Dec 20, 2020 at 9:51
  • Solution was to remove it from the other user, remove it from the root user, and install it on both, separately. Dec 21, 2020 at 14:16
0

I wrote a short script based on Lord Lulent solution, which works well for me

USER=barman
USER_HOME_PATH=~$USER
sudo ln -s $HOME/.zshrc   ${USER_HOME_PATH}/.zshrc
sudo ln -s $HOME/.oh-my-zsh   ${USER_HOME_PATH}/.oh-my-zsh
sudo ln -s $HOME/.p10k.zsh   ${USER_HOME_PATH}/.p10k.zsh
sudo chsh -s $(which zsh)  $USER
0

This might help with this use case https://stackoverflow.com/a/42193058/1408600

You could just install for the intended user using:

  1. wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh
  2. su $USER ./install.sh
0

Yes, it is possible to install OhMyZsh for different users.

If it is ok for you to have completely separated settings, you can provide different ZSH paths for each install, like this:

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

Cheers!

0

The only way that actually works out of all of the above (and seems to be the most natural one):

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

i.e. you should

  1. Assign your user directory's .oh-my-zsh path to ZSH environment variable
  2. Run the regular script

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .