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.

2
  • do you employ selinux ?
    – Sirex
    Sep 1, 2011 at 9:25
  • Sorry, no SELinux.
    – unixtippse
    Sep 1, 2011 at 17:54

2 Answers 2

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
3
  • 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 1, 2011 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 2, 2011 at 6:44
  • @Sirex: in addition to unixtippse's list there's 'popd' and others.
    – symcbean
    Sep 5, 2011 at 9:49
0

You could write a script inside .bashrc

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .