最近更新于 2023-06-02 12:12

环境

Ubuntu 20.04 VPS(终端使用 bash)

前言

前段时间搭建ChatGPT QQ机器人租了个服务器,然后一开始我就自己新建了一个用户,把默认的root和预创的admin用户禁止登录了,默认的终端配色是比较单调的,完全就是一种颜色,比如执行ls不会根据文件类型权限不同呈现不同的颜色的,所以要配置 ~/.bashrc 文件,这个文件通常是在打开新终端的时候会自动执行,配色之类的写在里面就会自动生效,但是这次却并没有生效,后面才发现是没 profile 文件

解决

在家目录下创建一个文件名为 .bash_profile

touch ~/.bash_profile

再向里面写入下面内容(我从另外一个服务器拷贝过来的)

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

之后连接的终端就会自动执行 .bashrc 文件了
file

作者 IYATT-yx