Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Clear your bash history - foil the snoops.

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
19 posts • Page 1 of 1
Author
Message
miunk
Apprentice
Apprentice
User avatar
Posts: 199
Joined: Tue Sep 24, 2002 3:00 pm

Clear your bash history - foil the snoops.

  • Quote

Post by miunk » Wed Mar 31, 2004 3:34 am

A simple tip from a simple mind. If you clear your web history often you should probably clear your bash history as well. Here's an easy way to do it every time you open a new terminal:

Add

Code: Select all

if [ -f ~/.bash_history ]; then
	rm ~/.bash_history
fi
to ~/.bashrc

where ~ is your home directory.
Top
Unne
l33t
l33t
User avatar
Posts: 616
Joined: Mon Jul 21, 2003 4:23 pm
Contact:
Contact Unne
Website

  • Quote

Post by Unne » Wed Mar 31, 2004 5:55 am

Bash history is quite useful, I wouldn't want to delete it every time I logged off. Mine is chmod 600, so isn't that going to stop people from snooping anyways? Unless you happen not to be the sysadmin of the PC you're using, and are worried what root might see.
Top
tomk
Bodhisattva
Bodhisattva
User avatar
Posts: 7221
Joined: Tue Sep 23, 2003 1:41 pm
Location: Sat in front of my computer

  • Quote

Post by tomk » Wed Mar 31, 2004 12:25 pm

You can achieve the same thing by making your .bash_history readable but not writeable:

Code: Select all

chmod 400 ~/.bash_history
You still get a history for each session as bash keeps your current history in memory, but it can't write it when it exits so it's not saved anywhere.
Search | Read | Answer | Report | Strip
Top
BobDylan
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 135
Joined: Wed Dec 10, 2003 7:02 pm
Location: On The Road

  • Quote

Post by BobDylan » Wed Mar 31, 2004 12:38 pm

You can achieve the same thing with

Code: Select all

export HISTFILE=/dev/null
in your .bashrc
Top
odegard
Guru
Guru
Posts: 324
Joined: Sat Mar 08, 2003 12:28 am
Location: Trondheim, NO

  • Quote

Post by odegard » Wed Mar 31, 2004 12:54 pm

I've set my history file to 15000 lines, steadily increased from 5000 etc. etc. I find it a huge resource, maybe I should find a script to cut redundant instances...hm... that's not a bad idea...
Top
alec
Apprentice
Apprentice
User avatar
Posts: 270
Joined: Fri Apr 19, 2002 3:02 am
Location: Here
Contact:
Contact alec
Website

  • Quote

Post by alec » Wed Mar 31, 2004 2:04 pm

"export HISTCONTROL=ignoredups" will stop bash from caching duplicate lines.
Top
odegard
Guru
Guru
Posts: 324
Joined: Sat Mar 08, 2003 12:28 am
Location: Trondheim, NO

  • Quote

Post by odegard » Thu Apr 01, 2004 4:02 am

Thanks, great tip!
Top
blue.sca
l33t
l33t
User avatar
Posts: 680
Joined: Thu Aug 28, 2003 4:51 pm
Location: Mainz, Germany

  • Quote

Post by blue.sca » Thu Apr 01, 2004 7:42 am

thats the tipp i ever wanted about bash ;) thx alot
geek by nature, linux by choice
i want my avatar back... thank you
:wq
Top
rojaro
l33t
l33t
Posts: 732
Joined: Mon May 06, 2002 4:56 pm
Contact:
Contact rojaro
Website

  • Quote

Post by rojaro » Fri Apr 02, 2004 11:36 am

I usually just do

Code: Select all

ln -sf ~/.bash_history /dev/null
but i think the method mentioned by BobDylan is probably the best
Top
bludger
Guru
Guru
Posts: 389
Joined: Wed Apr 09, 2003 7:14 am

  • Quote

Post by bludger » Fri Apr 02, 2004 5:41 pm

I actually like bash history and security is not a problem for me. I like the ignoredups hint earlier and will give it a go.

I have another related question. When are commands actually written to and read from the history file and is there some way of controlling this? It would be useful to be able to write a command in one terminal and the re-issue the command using Ctrl-R from another terminal.
Top
bludger
Guru
Guru
Posts: 389
Joined: Wed Apr 09, 2003 7:14 am

  • Quote

Post by bludger » Fri Apr 02, 2004 5:58 pm

Again, I write a question and then shortly thereafter find the answer myself.

From "man bash":
To append the history from the active shell to the history file: history -a
To read new entries from the history history file to the active shell: history -n

I also noticed that HISTCONTROL=ignoredups only prevents duplicates when the duplicate commands come one after the other. So if you enter:
command_1
command_2
command_1

they will all appear in the history.
Top
miunk
Apprentice
Apprentice
User avatar
Posts: 199
Joined: Tue Sep 24, 2002 3:00 pm

  • Quote

Post by miunk » Fri Apr 02, 2004 7:17 pm

To append the history from the active shell to the history file: history -a
To read new entries from the history history file to the active shell: history -n
I'll test when I get back on my gentoo machine, but I am wondering what exactly this means. I am assuming that it means across multiple terminals for the same user. This would be useful. What would be even more useful (although somewhat of a security concern) would be to share bash history between the "wheel" group users and the root user. So setting up my .bashrc and root's .bashrc with BobDylan's method:

Code: Select all

export HISTFILE=/usr/shared/.bash_history
and running:

Code: Select all

chown root /usr/shared/.bash_history
chgrp wheel /usr/shared/.bash_history
chmod 660 /usr/shared/.bash_history
I could set up a shared bash history, so when this happens:

Code: Select all

user@localhost$ emerge -u world
You are just a user idiot, you need to be root!
user@localhost$ su
Password:  
root@localhost$ 
BAM! Hit up and there it is.

Any ideas how to do this so that?

1) root can get to "wheel" users bash history.
2) "wheel" users can not get to root's bash history.
Top
Twink
Apprentice
Apprentice
User avatar
Posts: 178
Joined: Fri Dec 06, 2002 10:02 am
Location: New Zealand

  • Quote

Post by Twink » Tue Apr 06, 2004 3:30 am

miunk wrote:

Code: Select all

user@localhost$ emerge -u world
You are just a user idiot, you need to be root!
user@localhost$ su
Password:  
root@localhost$ 
BAM! Hit up and there it is.

Any ideas how to do this so that?

1) root can get to "wheel" users bash history.
2) "wheel" users can not get to root's bash history.
Personally I
alias emerge = 'sudo emerge'
on wheel accounts, dunno if thats the kinda thing you want.
Top
miunk
Apprentice
Apprentice
User avatar
Posts: 199
Joined: Tue Sep 24, 2002 3:00 pm

  • Quote

Post by miunk » Tue Apr 06, 2004 11:16 am

That is taking the easy way out. :lol:

sudo is the best.
Top
Gentree
Watchman
Watchman
User avatar
Posts: 5350
Joined: Tue Jul 01, 2003 12:51 am
Location: France, Old Europe

  • Quote

Post by Gentree » Fri May 07, 2004 12:03 pm

how can I increase the number of lines that I can scroll back in bash?

I'm not on about history here , just the console output so I can look back on error output.

Thx
Top
tomk
Bodhisattva
Bodhisattva
User avatar
Posts: 7221
Joined: Tue Sep 23, 2003 1:41 pm
Location: Sat in front of my computer

  • Quote

Post by tomk » Fri May 07, 2004 12:25 pm

Gentree wrote:how can I increase the number of lines that I can scroll back in bash?
AFAIK this isn't controlled by bash, but by your terminal. E.g. in xterm it's controlled by the -sl option, have a look at the man page for your terminal.
Search | Read | Answer | Report | Strip
Top
Gentree
Watchman
Watchman
User avatar
Posts: 5350
Joined: Tue Jul 01, 2003 12:51 am
Location: France, Old Europe

  • Quote

Post by Gentree » Fri May 07, 2004 12:31 pm

Thanks,

I'm talking *console* here , not xterm aterm or whatever under X.

login console :

#bash:

I'm sure there is something to put in .bashrc but the doc is HUGE and I have not found what I need .

Sorry if I was not explicit enough.

Thx.
Top
Darian
n00b
n00b
User avatar
Posts: 74
Joined: Thu Jun 12, 2003 3:01 am
Location: Albuquerque, NM, USA

  • Quote

Post by Darian » Fri May 07, 2004 7:41 pm

Regarding the original topic of history... I like to put this in my .bashrc

export HISTCONTROL=ignorespace

Any time I enter a command that I don't want going into my history I just type a space before the command.
Top
Negated Void
l33t
l33t
Posts: 670
Joined: Wed Dec 25, 2002 10:02 pm

  • Quote

Post by Negated Void » Fri May 07, 2004 7:54 pm

Call me the devil, but i like to play on my friend's box (I admin it for him, so i have root pass)

Anyways, i find if you don't want what you're doing in bash to show up in the history, just kill bash to logout.. :-D
Top
Post Reply

19 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic