• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : How to disable BASH shell history

by admin

Question: How to disable BASH shell history, so that it does not save users shell history?

Solution:

Add a line like the following to the end of /etc/profile or a new /etc/profile.d/*.sh file

unset HISTFILE

This will make each user’s bash shell to skip saving history files unless the users manually configure the HISTFILE variable.

caveat

There is no practical way to completely prevent users from saving their own bash shell history. Users can still get auto-saved shell history by manually declaring the HISTFILE variable. A user could add the following to their ~/.bash_profile or ~/.bashrc to create their own history files.

HISTFILE=$HOME/.my_history_file

To make it harder for users to get their bash processes to auto-save command history, take the following steps.

1. Add unset HISTFILE to global config as originally described here in the start of the post.

2. As root, take ownership of the ~/.bashrc and ~/.bash_profile files in EVERY user’s home directory, e.g.:

# chown root:root ~bob/.bashrc ~bob/.bash_profile

As root, make those same files (in EVERY user’s homedir) immutable, e.g.:

# chattr +i ~bob/.bashrc ~bob/.bash_profile

Note that performing these steps will not prevent a user from manually declaring the HISTFILE variable from the command-line each time they start a bash process. So if someone declares a variable HISTFILE, he can still be able to save the command history to a file.

Solaris : How to include date and timestamp in bash shell command history
CentOS / RHEL : How to get the date and time of executed command in the history command output
UNIX / Linux : Examples of bash history command to repeat last commands

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Disable/Enable Numa for Virtual Machine (XEN based)
  2. Basic nano Commands (Cheat Sheet)
  3. su: command not found
  4. How to Disable TLS 1.1 Cockpit port 9090
  5. Oracle Database Environment Variables and Their Functions
  6. chgrp Command Examples in Linux
  7. How to gzip all or specific files in Linux
  8. pdftoppm Command Examples in Linux
  9. efibootmgr Command Examples in Linux
  10. pkcon: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright