侧边栏壁纸
博主头像
空念文章-inless

行动起来,活在当下

  • 累计撰写 7 篇文章
  • 累计创建 1 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

更改 SSH 颜色

inless
2025-03-25 / 0 评论 / 0 点赞 / 35 阅读 / 0 字

1.编辑系统文件

CentOS/RHEL

编辑系统.bashrc文件

注意:.bashrc是一个隐藏的文件,如果无法打开需要用ls -a命令找到.bashrc文件,然后再打开即可;
编辑文件:vi ~/.bashrc
找到代码:#force_color_prompt=yes
替换其为:force_color_prompt=yes

继续编辑.bashrc文件,颜色设置在if [ "$color_prompt" = yes ]; then的下面一行,替换掉其代码即可;

  • 原始代码

    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  • 替换代码

    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]'

Debian/Ubuntu

  • 需在用户.bashrc 添加

force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]'
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

2.生效

source .bashrc        # CentOS/RHEL

0

评论区