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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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 enable additional scsi logging in CentOS/RHEL
  2. What is the refid in ntpq -p output?
  3. Linux OS Service ‘nscd’
  4. “passwd: Module is unknown” – error while changing the password in CentOS/RHEL 6
  5. “su: Authentication failure” – in Docker
  6. Cannot Increase “nproc” Value More Than 1024 in CentOS/RHEL 6
  7. iSCSI connection command examples (Cheat Sheet)
  8. Server Application Getting “connection refused” From Remote Servers [due to firewalld or iptables] – CentOS/RHEL 7
  9. CentOS / RHEL : How to disable ssh for non-root users (allowing ssh only for root user)
  10. How to Configure rsyslog Server to Accept Logs via SSL/TLS

You May Also Like

Primary Sidebar

Recent Posts

  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • How to Capture More Logs in /var/log/dmesg for CentOS/RHEL
  • Unable to Start RDMA Services on CentOS/RHEL 7
  • How to rename a KVM VM with virsh
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary