Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Clear your bash history - foil the snoops.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
miunk
Apprentice
Apprentice


Joined: 24 Sep 2002
Posts: 199

PostPosted: Wed Mar 31, 2004 3:34 am    Post subject: Clear your bash history - foil the snoops. Reply with quote

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:

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


to ~/.bashrc

where ~ is your home directory.
Back to top
View user's profile Send private message
Unne
l33t
l33t


Joined: 21 Jul 2003
Posts: 616

PostPosted: Wed Mar 31, 2004 5:55 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Wed Mar 31, 2004 12:25 pm    Post subject: Reply with quote

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

Code:
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
Back to top
View user's profile Send private message
BobDylan
Tux's lil' helper
Tux's lil' helper


Joined: 10 Dec 2003
Posts: 135
Location: On The Road

PostPosted: Wed Mar 31, 2004 12:38 pm    Post subject: Reply with quote

You can achieve the same thing with
Code:
export HISTFILE=/dev/null
in your .bashrc
Back to top
View user's profile Send private message
odegard
Guru
Guru


Joined: 08 Mar 2003
Posts: 324
Location: Trondheim, NO

PostPosted: Wed Mar 31, 2004 12:54 pm    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
alec
Apprentice
Apprentice


Joined: 19 Apr 2002
Posts: 270
Location: Here

PostPosted: Wed Mar 31, 2004 2:04 pm    Post subject: Reply with quote

"export HISTCONTROL=ignoredups" will stop bash from caching duplicate lines.
Back to top
View user's profile Send private message
odegard
Guru
Guru


Joined: 08 Mar 2003
Posts: 324
Location: Trondheim, NO

PostPosted: Thu Apr 01, 2004 4:02 am    Post subject: Reply with quote

Thanks, great tip!
Back to top
View user's profile Send private message
blue.sca
l33t
l33t


Joined: 28 Aug 2003
Posts: 680
Location: Mainz, Germany

PostPosted: Thu Apr 01, 2004 7:42 am    Post subject: Reply with quote

thats the tipp i ever wanted about bash ;) thx alot
_________________
geek by nature, linux by choice
i want my avatar back... thank you
:wq
Back to top
View user's profile Send private message
rojaro
l33t
l33t


Joined: 06 May 2002
Posts: 732

PostPosted: Fri Apr 02, 2004 11:36 am    Post subject: Reply with quote

I usually just do
Code:
ln -sf ~/.bash_history /dev/null

but i think the method mentioned by BobDylan is probably the best
Back to top
View user's profile Send private message
bludger
Guru
Guru


Joined: 09 Apr 2003
Posts: 389

PostPosted: Fri Apr 02, 2004 5:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
bludger
Guru
Guru


Joined: 09 Apr 2003
Posts: 389

PostPosted: Fri Apr 02, 2004 5:58 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
miunk
Apprentice
Apprentice


Joined: 24 Sep 2002
Posts: 199

PostPosted: Fri Apr 02, 2004 7:17 pm    Post subject: Reply with quote

Quote:

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:

export HISTFILE=/usr/shared/.bash_history


and running:

Code:

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:

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.
Back to top
View user's profile Send private message
Twink
Apprentice
Apprentice


Joined: 06 Dec 2002
Posts: 178
Location: New Zealand

PostPosted: Tue Apr 06, 2004 3:30 am    Post subject: Reply with quote

miunk wrote:

Code:

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.
Back to top
View user's profile Send private message
miunk
Apprentice
Apprentice


Joined: 24 Sep 2002
Posts: 199

PostPosted: Tue Apr 06, 2004 11:16 am    Post subject: Reply with quote

That is taking the easy way out. :lol:

sudo is the best.
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
Location: France, Old Europe

PostPosted: Fri May 07, 2004 12:03 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Fri May 07, 2004 12:25 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
Location: France, Old Europe

PostPosted: Fri May 07, 2004 12:31 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Darian
n00b
n00b


Joined: 12 Jun 2003
Posts: 74
Location: Albuquerque, NM, USA

PostPosted: Fri May 07, 2004 7:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Negated Void
l33t
l33t


Joined: 25 Dec 2002
Posts: 665

PostPosted: Fri May 07, 2004 7:54 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum