我想要一个系统范围的oh-my-zsh设置,但我不确定最好的"最好的"这个方法。我不打算询问个人偏好等,我只是不确定以下解决方案是否:
ln
我的本地用户配置似乎不对,因为向我的本地cfg添加漏洞并因此获得root权限非常容易。
将oh-my-zsh安装到/etc
可能也是一个安全漏洞,因为我根本就没有自己写过。
简单地编写我自己的个人.zshrc
将是我想尝试的最后一种方法,因为它非常耗时。
有什么建议吗?
答案 0 :(得分:13)
除非我误解了Caleb的标记答案,只是正常的每用户安装步骤,将.zshrc文件添加到skel目录并更改默认的新用户shell, 但它实际上没有工作或真正回答问题,因为每个用户仍然需要oh-my-zsh目录/ 仍需要每个用户将oh-my-zsh目录克隆到他们自己的文件夹中意味着它并没有真正安装在系统范围内,它只是自动给他们一个zshrc文件并将默认shell更改为zsh,但没有哦 - 我 - 每个用户文件夹中的zsh都会出错。
根据我对该问题的理解,它询问如何安装oh-my-zsh 系统范围,并将其安装在一个地方而不需要手动搞乱每个新的用户/在每个用户目录上有一个oh-my-zsh的git clone。假设情况如此,这就是我基于Arch Linux的AUR Package所做的事情,我通常使用但是在centos服务器上寻找相同的东西,但是这可以在任何发行版上完成。 归功于MarcinWieczorek和其他维护者,我只是改编了以下所以可以在非拱形发行版上做同样的事情。
如果你已经在root上安装了oh-my-zsh,请跳到第3步。这不是特定于发行版的,只是使用zURrc的AUR补丁文件
第1步
当然安装zsh
第2步
按正常方式安装oh-my-zsh作为root用户(显示wget方法,请参阅Calebs回答替代方案)
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
第3步
将安装移至/ usr / share,因此系统范围
#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
现在全局安装了oh-my-zsh,用户只需要zshrc文件。所以现在Caleb的答案就在这里,但是只需要执行以下操作,因为/etc/adduser.conf仅在debian上,而下面应该是distro独立的。
第4步
将其设置为新用户的默认设置
# 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
现在,真正安装了oh-my-zsh,所有新用户都自动将其应用于/ usr / share / oh-my-zsh / zshrc设置,而不是其他需要的步骤。
其他笔记
对于使用oh-my-zsh的任何已有用户:
cp /usr/share/oh-my-zsh/zshrc ~/.zshrc
答案 1 :(得分:8)
公平警告:这假设是Debian风格的linux,但这也适用于其他形式。这也假设您从头开始。
第1部分,安装:
您需要在系统范围内安装zsh,而不仅仅是为一个用户安装。 (你可能已经这样做了,但为了全面,我会把它包括在内)
确保您已安装zsh,只需:sudo apt-get install zsh
按照oh-my-zsh install指南进行操作,您可以:
使用curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
使用wget
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
第2部分,添加新用户时设置zsh:
您需要将其设置为新用户默认为zsh。在/etc/adduser.conf
文件中,修改一行:
DSHELL=/bin/sh
为:
DSHELL=/bin/zsh
您还应该为/etc/default/useradd
文件更改它,更改行:
SHELL=/bin/sh
为:
SHELL=/bin/zsh
第3部分,设置自定义主题。
我有一个自定义主题文件(here),我希望系统上的所有用户都有。首先,您应该将文件添加到.oh-my-zsh/themes
文件夹:
cp your_custom_style.zsh-theme ~/.oh-my-zsh/themes
接下来,修改主目录中的.zshrc
文件,将ZSH_THEME="default"
更改为ZSH_THEME="your_custom_style"
然后,使用:.zshrc
. ~/.zshrc
文件
第4部分,设置新用户的主目录。
我们需要在/etc/skel
目录中放置我们希望新用户拥有的任何文件,因为这是系统在创建新用户的主目录时复制的内容。有关详细信息,请参阅this sys admin guide。
复制用户的文件(您可能需要sudo):
cp -r .oh-my-zsh /etc/skel/
cp .zshrc /etc/skel
现在您将能够添加新用户,他们将拥有oh-my-zsh 默认使用您希望他们拥有的任何自定义主题。
如果您想将所有其他现有用户的shell更改为zsh,我建议您阅读this serverfault question。
答案 2 :(得分:3)
不那么猖獗,更方便,而且我认为更好的方法如下。首先执行以下操作:
sudo git clone https://github.com/robbyrussell/oh-my-zsh.git /etc/oh-my-zsh
sudo cp /etc/oh-my-zsh/templates/zshrc.zsh-template /etc/skel/.zshrc
sudo mkdir -p /etc/skel/.oh-my-zsh/cache
修改/etc/skel/.zshrc
:
# this line at the beginning of the file (line 5 currently)
export ZSH=$HOME/.oh-my-zsh
# has to be:
export ZSH=/etc/oh-my-zsh
export ZSH_CACHE_DIR=~/.oh-my-zsh/cache
然后修改/etc/default/useradd
并将第SHELL=...
行更改为SHELL=/bin/zsh
。
基本上都是这样。 (当然必须安装zsh
和git
。)
对于来自相应帐户的每个现有用户cp /ect/skel/.zshrc ~/.zshrc
。
答案 3 :(得分:1)
以ROOT身份登录
第1步:安装ZSH
# Download and extract ZSH
wget https://github.com/zsh-users/zsh/archive/zsh-5.8.tar.gz -P /tmp/demo/zsh
cd /tmp/demo/zsh
tar -xvzf zsh-*
cd zsh-zsh-5.8
# configure and make
sudo ./Util/preconfig
sudo ./configure
sudo make && sudo make install
# Add ZSH to the list of shells
echo /usr/local/bin/zsh | sudo tee -a /etc/shells
第2步:安装oh-my-zsh
# If you're running the Oh My Zsh install script as part of an automated install,
# you can pass the flag --unattended to the install.sh script.
# This will have the effect of not trying to change the default shell, and also won't
# run zsh when the installation has finished.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# Add oh-my-zsh to /usr/share
mv /root/.oh-my-zsh /usr/share
mv /usr/share/.oh-my-zsh /usr/share/oh-my-zsh
mv /root/.zshrc /usr/share/oh-my-zsh
mv /usr/share/oh-my-zsh/.zshrc /usr/share/oh-my-zsh/zshrc
# Modify zshrc to point to /usr/share/oh-my-zsh
sed -i 's|export ZSH="'"$HOME"'/.oh-my-zsh"|export ZSH="\/usr\/share\/oh-my-zsh"|g' /usr/share/oh-my-zsh/zshrc
第3步:添加其他功能(可选-在底部查看其他功能)
第4步:创建符号链接
# Create Symbolic Links to /etc/skel
sudo ln /usr/share/oh-my-zsh/zshrc /etc/skel/.zshrc
第5步:为根添加oh-my-zsh
# Change shell to ZSH for root
echo "$USER" | chsh -s /usr/local/bin/zsh
步骤6:为用户添加oh-my-zsh
# Change user
su - username
# Copy zshrc to $HOME for user
cp /usr/share/oh-my-zsh/zshrc ~/.zshrc
# Change shell to ZSH for user
echo "$USER" | chsh -s /usr/local/bin/zsh
OR
sudo -i -u username bash << EOF
cp /usr/share/oh-my-zsh/zshrc ~/.zshrc
echo username | chsh -s /usr/local/bin/zsh
EOF
额外:
将主题更改为powerlevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-/usr/share/oh-my-zsh/custom}/themes/powerlevel10k
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' /usr/share/oh-my-zsh/zshrc
启用自动校正
sed -i 's/# ENABLE_CORRECTION="true"/ENABLE_CORRECTION="true"/g' /usr/share/oh-my-zsh/zshrc
启用自动建议和语法突出显示
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-/usr/share/oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-/usr/share/oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
sed -i 's/plugins=(git)/plugins=(\n git\n zsh-autosuggestions\n zsh-syntax-highlighting\n)/' /usr/share/oh-my-zsh/zshrc
sed -i 's/plugins=(git)/plugins=(git)\nZSH_DISABLE_COMPFIX=true/' /usr/share/oh-my-zsh/zshrc
添加Nord dircolors
git clone --depth=1 https://github.com/arcticicestudio/nord-dircolors.git /tmp/demo/dircolors
mv /tmp/demo/dircolors/src/dir_colors /usr/share/
cd /usr/share/
mv /usr/share/dir_colors /usr/share/.dir_colors
tee -a /usr/share/oh-my-zsh/zshrc >/dev/null <<'EOF'
test -r "/usr/share/.dir_colors" && eval $(dircolors /usr/share/.dir_colors)
EOF
答案 4 :(得分:0)
我结合了 cFINNY 的答案,阅读并理解了oh-my-zsh安装脚本,他的答案中的AUR补丁,并修复了损坏的adduser
命令来进行此安装在FROM ubuntu:bionic
(Ubuntu 18.04)Dockerfile中:
RUN git clone \
-c core.eol=lf \
-c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 \
--branch master \
https://github.com/ohmyzsh/ohmyzsh.git \
/usr/share/oh-my-zsh \
# Adapt zshrc template
&& cd /usr/share/oh-my-zsh/ \
&& cp templates/zshrc.zsh-template zshrc \
&& sed -i 's/export ZSH=$HOME\/.oh-my-zsh/export ZSH=\/usr\/share\/oh-my-zsh/g' zshrc \
&& sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' zshrc \
&& sed -i 's/source $ZSH\/oh-my-zsh.sh//g' zshrc \
&& sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="bira"/g' zshrc \
&& echo '\n \
\n \
ZSH_CACHE_DIR=$HOME/.cache/oh-my-zsh \n \
if [[ ! -d $ZSH_CACHE_DIR ]]; then \n \
mkdir -p $ZSH_CACHE_DIR \n \
fi \n \
\n \
source $ZSH/oh-my-zsh.sh \n \
' >> zshrc \
# Copy zshrc template to $HOME on user creation
&& ln /usr/share/oh-my-zsh/zshrc /etc/skel/.zshrc \
# Setting the default shell for new users has no effect since:
# 1. The default shell is specified when creating new users in entrypoint
# 2. The `ade enter` command will execute `bash` anyways
&& sed -i 's/DSHELL=\/bin\/bash/DSHELL=\/bin\/zsh/g' /etc/adduser.conf
答案 5 :(得分:0)
还有一种简单的方法可以做到这一点: 以root用户登录并安装zsh
sudo su
apt-get install zsh
然后以系统的另一个用户身份登录:
su username
export ZSH=/home/username/.oh-my-zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
对所有需要 oh-my-zsh