加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Bash – / etc / profile,登录时过多的只读变量消息

发布时间:2020-12-15 21:16:03 所属栏目:安全 来源:网络整理
导读:在Ubuntu Linux上,使用Bash,我在/ etc / profile上设置了登录时的只读变量. 这是我的/ etc / profile(我的添加内容位于此文件的底部): # Check for interactive bash and that we haven't already been sourced.[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$
在Ubuntu Linux上,使用Bash,我在/ etc / profile上设置了登录时的只读变量.
这是我的/ etc / profile(我的添加内容位于此文件的底部):

# Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return

# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then
    if shopt -q progcomp && [ -r /etc/bash_completion ]; then
        # Source completion code.
        . /etc/bash_completion
    fi
fi
unset bash bmajor bminor

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1),ksh(1),ash(1),...).

TZ='America/Kentucky/Louisville'; export TZ

if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
  . $i
fi
done
unset i
fi

if [ "$PS1" ]; then
if [ "$BASH" ]; then
PS1='u@h:w$'
if [ -f /etc/bash.bashrc ]; then
    . /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
  PS1='# '
else
  PS1='$'
fi
fi
fi

 **# My Additions**

umask 077
shopt -s histappend
shopt -s histverify

export HISTFILE=~/.bash_history
export HISTFILESIZE=1000000000
export HISTSIZE=5000
export HISTCONTROL=""
export HISTIGNORE=""
export HISTTIMEFORMAT="%F %T"

readonly HISTFILE
readonly HISTFILESIZE
readonly HISTSIZE
readonly HISTCONTROL
readonly HISTIGNORE
readonly HISTTIMEFORMAT
readonly HISTCMD
readonly HOME
readonly PATH

echo -e "Subject: Login from $(/usr/bin/whoami) on $(/bin/hostname) at          $(/bin/date)nn$(/usr/bin/last -n 10 -F)n" 
| /usr/sbin/ssmtp user@company.com

export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo "$$$USER $(history    1)"|/usr/bin/logger -p user.alert -t shell.log'
readonly PROMPT_COMMAND

这是位于/etc/profile.d中的bash_completion文件:

# Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return

# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then
if shopt -q progcomp && [ -r /etc/bash_completion ]; then
    # Source completion code.
    . /etc/bash_completion
fi
fi
unset bash bmajor bminor

我的问题是,当我登录时,在发送提示之前,我会被大量的bash消息“淹没”:

....
-bash: PATH: readonly variable
-bash: PATH: readonly variable
-bash: PATH: readonly variable
-bash: PATH: readonly variable
-bash: HISTFILE: readonly variable
-bash: HISTFILESIZE: readonly variable
-bash: HISTSIZE: readonly variable
-bash: HISTCONTROL: readonly variable
-bash: HISTIGNORE: readonly variable
-bash: HISTTIMEFORMAT: readonly variable
-bash: PROMPT_COMMAND: readonly variable

我的第一个问题是为什么有这么多PATH:只读变量消息15具有完整输出?我的第二个问题是如何在登录时停止显示这些消息.

在此先感谢您的帮助!

解决方法

病人:“医生,我这样做会疼.”
医生:“不要那样做.”

不要将这些变量设置为只读.

您收到这些错误消息的原因是这些变量正在/ etc / profile之后执行的文件中被修改(例如?/ .bashrc).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读