kali安装Zsh(以及踩的坑)

有目标就不怕路远。年轻人.无论你现在身在何方.重要的是你将要向何处去。只有明确的目标才能助你成功。没有目标的航船.任何方向的风对他来说都是逆风。因此,再遥远的旅程,只要有目标.就不怕路远。没有目标,哪来的劲头?一车尔尼雷夫斯基

导读:本篇文章讲解 kali安装Zsh(以及踩的坑),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

写这篇文章的时候kali 还没有引入zsh,现在Kali Linux 2020.3 稳定版已发布,引入zsh,并宣布了从 bash 切换至 zsh 的计划,2020.4 将默认使用 zsh

既然都已经是kali了,也谈一下Msfvenom命令自动补全方法,配合Zsh使用,配置方式参考潇湘信安的文章
视频版教程参见哔哩哔哩


首先,kalidebian系的,所以虽然我写的关于kali的方法也适用于其它debian系的系统,譬如ubuntu,以下内容综合了其他博主的内容。
用过虚拟机的都知道,频繁切换虚拟机和物理机很不方便,尤其是像现在写博客时,下面的内容是我使用windows Terminal通过ssh连接kali来操作的,特此声明!

初识Zsh

以下内容引自
“OG完美主义者”,原文地址
推荐阅读:“Zsh 入门”,原文地址
推荐阅读:“给 Zsh 添加主题和插件”,原文地址
推荐阅读:“使用zsh+agnoster出现乱码”,原文地址

目前大部分 Linux 发行版的默认 Shell 仍然是 BASH,有个别例外。Z shell(Zsh)是另外一款 shell 命令解释器,它是Bourne Shell(sh)的扩展版本,但对 Bourne shell 做出了大量改进,同时加入了 Bash、ksh 及 tcsh 的某些功能,是目前特别受 Linux 粉丝喜欢的一个 Shell 程序。

Zsh是怎么来的

Zsh 最早是保罗·弗斯塔德于1990年在普林斯顿大学求学期间编写的。Zsh 的名称源于耶鲁大学的邵中(Zhong Shao)教授,由于邵教授的电脑用户名就是为 zsh,所以这个新 Shell 程序也就因此得名了。

Zsh有哪些特性

Zsh 拥有很多友好的特性,因此一经推出就受到很多Linux爱好者的狂热追随。它最吸引人的特性包括:

默认支持命令选项和参数的自动补全功能
无需外部程序即可通过文件扩展匹配文件(自动识别大小写)
在单缓冲区内编辑多行命令
拼写检查及多种兼容模式
支持大量扩展主题和插件

获取Zsh

安装Zsh

zsh 的安装命令如下:

sudo apt-get install zsh

安装完成之后,输入which zsh你可以看到zsh的安装目录,选择 zsh 文件的路径,将其设置为系统的默认 shell,重启系统后,默认 shell 就是 zsh 了!

➜  ~ which zsh    找到zsh的所在路径
/usr/bin/zsh
➜  ~ chsh -s /usr/bin/zsh    把zsh作为默认shell
密码:
➜  ~ 

使用oh-my-zsh

和 Bash 的默认用户配置文件 .bashrc 类似,Zsh 安装之后也会在当前用户的主目录下生成 .zshrc 配置文件。你可以手动编辑这个文件,让它更好的满足你的日常使用习惯,当然这对于初学者并不轻松。

为了更好的配置 Zsh,开源社区开发了 oh-my-zsh 框架,用于方便的管理 Zsh 的配置工作。所以接下来我们需要执行 oh-my-zsh 的安装指令:

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

此处会出现一个大坑,你会发现操作无效,像这样
在这里插入图片描述
大概率是大中华局域网的原因,想办法访问国际互联网后发现安装oh-my-zsh要用的那个脚本是这样的
在这里插入图片描述
我这里把上面的内容复制粘贴到了下面,把下面的内容复制粘贴到kali里面,命名文件为install.sh

#!/bin/sh
#
# This script should be run via curl:
#   sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# or wget:
#   sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#
# As an alternative, you can first download the install script and run it afterwards:
#   wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
#   sh install.sh
#
# You can tweak the install behavior by setting variables when running the script. For
# example, to change the path to the Oh My Zsh repository:
#   ZSH=~/.zsh sh install.sh
#
# Respects the following environment variables:
#   ZSH     - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
#   REPO    - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
#   REMOTE  - full remote URL of the git repo to install (default: GitHub via HTTPS)
#   BRANCH  - branch to check out immediately after install (default: master)
#
# Other options:
#   CHSH       - 'no' means the installer will not change the default shell (default: yes)
#   RUNZSH     - 'no' means the installer will not run zsh after the install (default: yes)
#   KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
#
# You can also pass some arguments to the install script to set some these options:
#   --skip-chsh: has the same behavior as setting CHSH to 'no'
#   --unattended: sets both CHSH and RUNZSH to 'no'
#   --keep-zshrc: sets KEEP_ZSHRC to 'yes'
# For example:
#   sh install.sh --unattended
#
set -e

# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}

# Other options
CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no}


command_exists() {
	command -v "$@" >/dev/null 2>&1
}

error() {
	echo ${RED}"Error: $@"${RESET} >&2
}

setup_color() {
	# Only use colors if connected to a terminal
	if [ -t 1 ]; then
		RED=$(printf '\033[31m')
		GREEN=$(printf '\033[32m')
		YELLOW=$(printf '\033[33m')
		BLUE=$(printf '\033[34m')
		BOLD=$(printf '\033[1m')
		RESET=$(printf '\033[m')
	else
		RED=""
		GREEN=""
		YELLOW=""
		BLUE=""
		BOLD=""
		RESET=""
	fi
}

setup_ohmyzsh() {
	# Prevent the cloned repository from having insecure permissions. Failing to do
	# so causes compinit() calls to fail with "command not found: compdef" errors
	# for users with insecure umasks (e.g., "002", allowing group writability). Note
	# that this will be ignored under Cygwin by default, as Windows ACLs take
	# precedence over umasks except for filesystems mounted with option "noacl".
	umask g-w,o-w

	echo "${BLUE}Cloning Oh My Zsh...${RESET}"

	command_exists git || {
		error "git is not installed"
		exit 1
	}

	if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
		error "Windows/MSYS Git is not supported on Cygwin"
		error "Make sure the Cygwin git package is installed and is first on the \$PATH"
		exit 1
	fi

	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 "$BRANCH" "$REMOTE" "$ZSH" || {
		error "git clone of oh-my-zsh repo failed"
		exit 1
	}

	echo
}

setup_zshrc() {
	# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
	# with datestamp of installation that moved them aside, so we never actually
	# destroy a user's original zshrc
	echo "${BLUE}Looking for an existing zsh config...${RESET}"

	# Must use this exact name so uninstall.sh can find it
	OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
	if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
		# Skip this if the user doesn't want to replace an existing .zshrc
		if [ $KEEP_ZSHRC = yes ]; then
			echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
			return
		fi
		if [ -e "$OLD_ZSHRC" ]; then
			OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
			if [ -e "$OLD_OLD_ZSHRC" ]; then
				error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
				error "re-run the installer again in a couple of seconds"
				exit 1
			fi
			mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"

			echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
				"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
		fi
		echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
		mv ~/.zshrc "$OLD_ZSHRC"
	fi

	echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"

	sed "/^export ZSH=/ c\\
export ZSH=\"$ZSH\"
" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
	mv -f ~/.zshrc-omztemp ~/.zshrc

	echo
}

setup_shell() {
	# Skip setup if the user wants or stdin is closed (not running interactively).
	if [ $CHSH = no ]; then
		return
	fi

	# If this user's login shell is already "zsh", do not attempt to switch.
	if [ "$(basename "$SHELL")" = "zsh" ]; then
		return
	fi

	# If this platform doesn't provide a "chsh" command, bail out.
	if ! command_exists chsh; then
		cat <<-EOF
			I can't change your shell automatically because this system does not have chsh.
			${BLUE}Please manually change your default shell to zsh${RESET}
		EOF
		return
	fi

	echo "${BLUE}Time to change your default shell to zsh:${RESET}"

	# Prompt for user choice on changing the default login shell
	printf "${YELLOW}Do you want to change your default shell to zsh? [Y/n]${RESET} "
	read opt
	case $opt in
		y*|Y*|"") echo "Changing the shell..." ;;
		n*|N*) echo "Shell change skipped."; return ;;
		*) echo "Invalid choice. Shell change skipped."; return ;;
	esac

	# Check if we're running on Termux
	case "$PREFIX" in
		*com.termux*) termux=true; zsh=zsh ;;
		*) termux=false ;;
	esac

	if [ "$termux" != true ]; then
		# Test for the right location of the "shells" file
		if [ -f /etc/shells ]; then
			shells_file=/etc/shells
		elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
			shells_file=/usr/share/defaults/etc/shells
		else
			error "could not find /etc/shells file. Change your default shell manually."
			return
		fi

		# Get the path to the right zsh binary
		# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
		# 2. If that fails, get a zsh path from the shells file, then check it actually exists
		if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
			if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
				error "no zsh binary found or not present in '$shells_file'"
				error "change your default shell manually."
				return
			fi
		fi
	fi

	# We're going to change the default shell, so back up the current one
	if [ -n "$SHELL" ]; then
		echo $SHELL > ~/.shell.pre-oh-my-zsh
	else
		grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
	fi

	# Actually change the default shell to zsh
	if ! chsh -s "$zsh"; then
		error "chsh command unsuccessful. Change your default shell manually."
	else
		export SHELL="$zsh"
		echo "${GREEN}Shell successfully changed to '$zsh'.${RESET}"
	fi

	echo
}

main() {
	# Run as unattended if stdin is closed
	if [ ! -t 0 ]; then
		RUNZSH=no
		CHSH=no
	fi

	# Parse arguments
	while [ $# -gt 0 ]; do
		case $1 in
			--unattended) RUNZSH=no; CHSH=no ;;
			--skip-chsh) CHSH=no ;;
			--keep-zshrc) KEEP_ZSHRC=yes ;;
		esac
		shift
	done

	setup_color

	if ! command_exists zsh; then
		echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
		exit 1
	fi

	if [ -d "$ZSH" ]; then
		cat <<-EOF
			${YELLOW}You already have Oh My Zsh installed.${RESET}
			You'll need to remove '$ZSH' if you want to reinstall.
		EOF
		exit 1
	fi

	setup_ohmyzsh
	setup_zshrc
	setup_shell

	printf "$GREEN"
	cat <<-'EOF'
		         __                                     __
		  ____  / /_     ____ ___  __  __   ____  _____/ /_
		 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
		/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
		\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
		                        /____/                       ....is now installed!


		Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugins, themes, and options.

		• Follow us on Twitter: https://twitter.com/ohmyzsh
		• Join our Discord server: https://discord.gg/ohmyzsh
		• Get stickers, shirts, coffee mugs and other swag: https://shop.planetargon.com/collections/oh-my-zsh

	EOF
	printf "$RESET"

	if [ $RUNZSH = no ]; then
		echo "${YELLOW}Run zsh to try it out.${RESET}"
		exit
	fi

	exec zsh -l
}

main "$@"

安装oh-my-zsh

给脚本加可执行权限:chmod +x install.sh
执行脚本:./install.sh
在这里插入图片描述

新的终端Zsh

安装脚本会在用户主目录下生成 .oh-my-zsh 目录,其中的 themes 目录中默认会包含140多个主题文件,你可以按照自己的喜好从中选择,你下面看到的主题是Zsh的默认主题:ZSH_THEME="robbyrussell"oh-my-zsh包含了所有的主题,zshrc是需要修改的配置文件
在这里插入图片描述

修改主题

选择一个什么样的主题,可以去zsh的github上预览,选择一个你喜欢的主题,地址
大部分的主题是非常易于安装和使用的,仅仅需要改变 .zshrc 文件中的配置选项然后重新载入配置文件。其他的主题可能需要一些额外的配置。例如,为了使用 agnoster 主题,你必须先安装 Powerline 字体。这是一个开源字体,如果你使用 Linux 操作系统的话,这个字体很可能在你的软件库中存在。在做进一步操作之前,一个好的习惯是备份文件,我这里先备份以下原始的zshrc文件cp ~/.zshrc ~/.zshrc.bak,我这里确认使用agnoster主题,输入vim ~/.zshrc来修改主题:
你会看到这样的界面,把其中的robbyrussell替换为你喜欢的主题名字,然后保存退出
在这里插入图片描述
输入source ~/.zshrc使配置文件重新加载生效

主题排雷

可能你选择的主题能够正常使用,而我选择的主题会出错,这个官方也给出了说明,下面来说一下怎样解决agnoster主题乱码问题
在这里插入图片描述
安装 Powerline 字体:

sudo apt-get install fonts-powerline

在配置文件中更改你的主题:

sed -i 's/_THEME=\"linuxonly\"/_THEME=\"agnoster\"/g' ~/.zshrc

重新启动你的 Sehll(一个简单的 source 命令并不会起作用)。一旦重启,你就可以看到新的主题:
在这里插入图片描述
你看到的上面那个就是我kali的主题,而我windows终端显示出来的是下面的样子,尝试了网上几乎所有的办法依然没法解决,暂时选择更换为其他主题,唉::>_<::
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/134385.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!