我怎样才能获得安全的系统级 oh-my-zsh 配置?
How can I get a secure system-wide oh-my-zsh configuration?
我想要一个系统范围的 oh-my-zsh 设置,但我不确定 "best" 的方法是什么。个人喜好之类的问题我无意询问,只是不确定下面的解决方案是不是:
ln
我的本地用户配置某处似乎不对,因为在我的本地 cfg 中添加漏洞并因此获得 root 权限将非常容易。
将 oh-my-zsh 安装到 /etc
也可能是一个安全漏洞,因为我根本就没有自己写过它。
简单地写我自己的 .zshrc
是我最不想尝试的方法,因为它非常耗时。
有什么建议吗?
公平警告:这采用 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
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.
如果您想将所有其他现有用户的 shell 更改为 zsh,我建议您阅读 this serverfault question。
除非我误解了 Caleb 的标记答案只是 正常 per-user 安装 步骤,将 .zshrc 文件添加到 skel 目录并更改默认值new-user shell, 但它实际上并没有起作用或没有真正回答问题 因为每个用户仍然 需要oh-my-zsh dir/would 仍然需要每个用户将 oh-my-zsh 目录克隆到他们自己的文件夹中,这意味着它并没有真正安装在系统范围内 ,它只是自动给他们一个zshrc 文件并将默认 shell 更改为 zsh,但如果每个用户文件夹中没有 oh-my-zsh,它将出错。
根据我对这个问题的理解,它询问如何安装 oh-my-zsh system-wide 也就是将它安装在一个地方而不需要手动搞乱在每个新的 user/having 上,每个用户目录上的 oh-my-zsh 的 git 克隆。假设是这种情况,这就是我基于 Arch Linux 的 AUR 包所做的,我通常使用但在 centos 服务器上寻找相同的包,但是这可以在任何发行版上完成。 归功于 MarcinWieczorek 和其他维护者,我刚刚改编了下面的内容,因此可以在 non-arch 发行版上做同样的事情。
如果您已经在 root 上安装了 oh-my-zsh,请跳到第 3 步。这不是特定于发行版的,只是使用 zshrc[=14 的 AUR 补丁文件=]
第 1 步
当然要安装zsh
步骤#2
以 root 身份正常安装 oh-my-zsh(显示 wget 方法,参见 Calebs 的替代答案)
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
步骤#3
将安装移动到 /usr/share 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
现在 oh-my-zsh 已全局安装,用户只需要那个 zshrc 文件。所以现在是 Caleb 的答案出现的地方,尽管只需执行以下操作,因为 /etc/adduser.conf 仅在 debian 上,而下面应该是独立于发行版的。
步骤 #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 的 true 安装,所有新用户都会自动应用 /usr/share/oh-my-zsh/zshrc 设置无需其他步骤。
杂项注释
任何 pre-existing 用户 oh-my-zsh:
cp /usr/share/oh-my-zsh/zshrc ~/.zshrc
- 您可以在 /usr/share/oh-my-zsh/zshrc
中设置 新用户 OMZ 默认值
- 自动更新被禁用 因为新用户没有更新 /usr/share/oh-my-zsh 文件的权限
- 要更新 oh-my-zsh 只需 cd 到 /usr/share/oh-my-zsh/ 和 运行 'sudo git pull'
- oh-my-zsh 缓存将在 ~/.oh-my-zsh-cache/(自动创建)
下的每个用户目录中处理 per-user
如果你想在系统范围内安装 Oh-My-Zsh,覆盖最少数量文件的便捷方法是:
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
:
- 编辑行
export ZSH=$HOME/.oh-my-zsh
(当前为第 5 行)
- 将行更改为:
export ZSH=/etc/oh-my-zsh
export ZSH_CACHE_DIR=~/.oh-my-zsh/cache
然后编辑 /etc/default/useradd
并将行 SHELL=...
更改为 SHELL=/bin/zsh
。
基本上就这些了(当然,git和zsh必须已经安装)
要更新现有用户:以他们的身份登录并 cp /etc/skel/.zshrc ~/.zshrc
更新:请勿编辑。我刚刚回滚了一个完全搞砸的编辑!
我结合了 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
以 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:创建符号 link
# Create Symbolic Links to /etc/skel
sudo ln /usr/share/oh-my-zsh/zshrc /etc/skel/.zshrc
第 5 步:为 root 添加 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
或
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
还有一个简单的方法可以做到这一点:
以 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
的用户执行相同的程序
我想要一个系统范围的 oh-my-zsh 设置,但我不确定 "best" 的方法是什么。个人喜好之类的问题我无意询问,只是不确定下面的解决方案是不是:
ln
我的本地用户配置某处似乎不对,因为在我的本地 cfg 中添加漏洞并因此获得 root 权限将非常容易。将 oh-my-zsh 安装到
/etc
也可能是一个安全漏洞,因为我根本就没有自己写过它。简单地写我自己的
.zshrc
是我最不想尝试的方法,因为它非常耗时。
有什么建议吗?
公平警告:这采用 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
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.
如果您想将所有其他现有用户的 shell 更改为 zsh,我建议您阅读 this serverfault question。
除非我误解了 Caleb 的标记答案只是 正常 per-user 安装 步骤,将 .zshrc 文件添加到 skel 目录并更改默认值new-user shell, 但它实际上并没有起作用或没有真正回答问题 因为每个用户仍然 需要oh-my-zsh dir/would 仍然需要每个用户将 oh-my-zsh 目录克隆到他们自己的文件夹中,这意味着它并没有真正安装在系统范围内 ,它只是自动给他们一个zshrc 文件并将默认 shell 更改为 zsh,但如果每个用户文件夹中没有 oh-my-zsh,它将出错。
根据我对这个问题的理解,它询问如何安装 oh-my-zsh system-wide 也就是将它安装在一个地方而不需要手动搞乱在每个新的 user/having 上,每个用户目录上的 oh-my-zsh 的 git 克隆。假设是这种情况,这就是我基于 Arch Linux 的 AUR 包所做的,我通常使用但在 centos 服务器上寻找相同的包,但是这可以在任何发行版上完成。 归功于 MarcinWieczorek 和其他维护者,我刚刚改编了下面的内容,因此可以在 non-arch 发行版上做同样的事情。
如果您已经在 root 上安装了 oh-my-zsh,请跳到第 3 步。这不是特定于发行版的,只是使用 zshrc[=14 的 AUR 补丁文件=]
第 1 步
当然要安装zsh
步骤#2
以 root 身份正常安装 oh-my-zsh(显示 wget 方法,参见 Calebs 的替代答案)
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
步骤#3
将安装移动到 /usr/share 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
现在 oh-my-zsh 已全局安装,用户只需要那个 zshrc 文件。所以现在是 Caleb 的答案出现的地方,尽管只需执行以下操作,因为 /etc/adduser.conf 仅在 debian 上,而下面应该是独立于发行版的。
步骤 #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 的 true 安装,所有新用户都会自动应用 /usr/share/oh-my-zsh/zshrc 设置无需其他步骤。
杂项注释
任何 pre-existing 用户 oh-my-zsh:
cp /usr/share/oh-my-zsh/zshrc ~/.zshrc
- 您可以在 /usr/share/oh-my-zsh/zshrc 中设置 新用户 OMZ 默认值
- 自动更新被禁用 因为新用户没有更新 /usr/share/oh-my-zsh 文件的权限
- 要更新 oh-my-zsh 只需 cd 到 /usr/share/oh-my-zsh/ 和 运行 'sudo git pull'
- oh-my-zsh 缓存将在 ~/.oh-my-zsh-cache/(自动创建) 下的每个用户目录中处理 per-user
如果你想在系统范围内安装 Oh-My-Zsh,覆盖最少数量文件的便捷方法是:
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
:
- 编辑行
export ZSH=$HOME/.oh-my-zsh
(当前为第 5 行) - 将行更改为:
export ZSH=/etc/oh-my-zsh
export ZSH_CACHE_DIR=~/.oh-my-zsh/cache
然后编辑 /etc/default/useradd
并将行 SHELL=...
更改为 SHELL=/bin/zsh
。
基本上就这些了(当然,git和zsh必须已经安装)
要更新现有用户:以他们的身份登录并 cp /etc/skel/.zshrc ~/.zshrc
更新:请勿编辑。我刚刚回滚了一个完全搞砸的编辑!
我结合了 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
以 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:创建符号 link
# Create Symbolic Links to /etc/skel
sudo ln /usr/share/oh-my-zsh/zshrc /etc/skel/.zshrc
第 5 步:为 root 添加 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
或
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
还有一个简单的方法可以做到这一点: 以 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