Linux系统环境变量配置文件

Linux 系统基础之环境变量及其配置文件


在这里插入图片描述

一、环境变量配置文件

  • /etc/profile #全局配置文件
  • /etc/profile.d/*.sh #全局配置文件,lang语言
  • ~/.bash_profile #用户特定配置文件 定义用户environment
  • ~/.bashrc #用户特定配置文件, 定义用户别名(alias)
  • /etc/bashrc #全局配置文件,提示符(PS1)

二、配置文件的作用

/etc 目录下的对所有用户生效

~/ 目录下的仅对当前用户生效

  1. 系统加载的登录过程的基本过程如下:
/etc/profile
~/.bash_profile
~/.bashrc
/etc/bashrc
命令提示符
/etc/profile.d/*.sh
/etc/profile.d/lang.sh

流程一,开始启动登录:

/etc/profile
/etc/profile.d/*.sh
/etc/profile.d/lang.sh

流程二,加载完lang.sh 等,加载环境变量配置文件:

/etc/profile
~/.bash_profile
~/.bashrc
/etc/bashrc
命令提示符

流程三:通过su - 命令登录,只需要重新加载 /etc/bashrc文件,和lang.sh 等文件:

/etc/bashrc
/etc/profile.d/*.sh
/etc/profile.d/lang.sh
命令提示符

案例一、系统环境变量的加载过程演示:

# 最初登录系统,加载系统环境变量配置文件流程
/etc/profile
.bash_profile
.bashrc
/etc/bashrc
# 通过su 命令切换root 用户,环境变量的加载流程
[chenman@localhost ~]$ su
Password:
~/.bashrc
/etc/bashrc
[root@localhost chenman]# exit
# 通过su - 命令切换root 用户,环境变量的加载流程
[chenman@localhost ~]$ su -
Password:
Last login: Fri Mar 20 17:40:47 CST 2020 on pts/0
/etc/profile
~/.bash_profile
~/.bashrc
/etc/bashrc

默认登录环境变量加载流程如下:

/etc/profile
~/.bash_profile
~/.bashrc
/etc/bashrc
命令提示符

su 切换用户后,环境变量的加载流程如下:

~/.bashrc
/etc/bashrc
命令提示符

su - 切换用户后,环境变量加载流程如下:

/etc/profile
~/.bash_profile
~/.bashrc
/etc/bashrc
命令提示符

通过如上的案例演示,可得出:
默认登录会按流程加载环境变量,su命令切换只加载~/.bashrc/etc/bashrc 配置文件,su -则会和默认登录一样,按流程加载环境变量。因此,在我们需要添加环境变量时需要按使用场景声明变量。
注:文件的最高权限是 666

​ 目录的最高权限是 777 x 权限对于目录是可以 cd

umask定义的权限是系统默认权限中准备丢弃的权限,umask 值是通过字母值相减得到(异或);

例如:

umask=022 则创建的

文件的默认权限是 rw-rw-rw- ----w–w- = rw-r–r-- 644

目录的默认权限是 rwxrwxrwx ----w–w- = rwxr-xr-x 755

三、其他配置文件

  1. 注销时生效的环境变量配置文件 ~/.bash_logout

    注销时可以执行一些指定的命令。

  2. 历史命令 ~/.bash_history

  3. 本地终端登录欢迎信息 :(警告信息)/etc/issue 远程失效

    1. 远程终端显示提示信息: /etc/issue.net

      1. 转移字符在 /etc/issue.net 中不能使用
      2. 在ssh 配置文件 /etc/ssh/sshd_config 决定,加入”Banner /etc/issue.net“ ,并重启服务。
    2. 登陆后欢迎信息: /etc/motd

/etc/ssh/sshd_config 决定,加入”Banner /etc/issue.net“ ,并重启服务。

  1. 登陆后欢迎信息: /etc/motd

    不管远程还是本地登录,均可以显示文件中的信息!

发布了55 篇原创文章 · 获赞 20 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/AMimiDou_212/article/details/104994421