0

Given the following directory:

drwx------ 2 joe joe 4096 Jan 11  2010 /home/joe

Is there a way for me as the user root, to avoid accidentally cd-ing into this directory?

I'm not looking for actual permission enforcement, but for some setting (e.g. in the bash shell) that helps the root user avoid such a "private" directory.

MadHatter
  • 79,770
  • 20
  • 184
  • 232
unixtippse
  • 880
  • 1
  • 6
  • 13

2 Answers2

3

There's no way of preventing root from accessing the directory - within a Unix system root is omnipotent.

As to accidentally doing it.....it depends on what you are using to access the directory.

You might try....

export PS1="\u@\h [\$(check_path.sh)]>

Where check_path.sh is something like...

#!/bin/bash

if [ `whoami` = 'root' -a `pwd` = '/home/joe'] ; then
   echo -n "!!!!!!accessing /home/joe as root !!!!!!!!!"
fi
symcbean
  • 21,009
  • 1
  • 31
  • 52
  • I'm tempted to accept this as the answer, just because of the creativity. :-) What about wrapping cd into a shell alias that checks what's ahead? Handling all the cd use cases (cd, cd -, cd ~, cd ~/foo, cd ~foo/../foo) sounds a bit overkill, though. – unixtippse Sep 01 '11 at 18:01
  • the cd wrapper alias isn't as hard as you'd think, but it may well break shell scripts if you output a "do you want to continue" type message. – Sirex Sep 02 '11 at 06:44
  • @Sirex: in addition to unixtippse's list there's 'popd' and others. – symcbean Sep 05 '11 at 09:49
0

You could write a script inside .bashrc

something like ... if [ command == "cd /home/joe" ] do ask done

Nikolaidis Fotis
  • 2,032
  • 11
  • 13