Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
do you employ selinux ? –  Sirex Sep 1 '11 at 9:25
    
Sorry, no SELinux. –  unixtippse Sep 1 '11 at 17:54

2 Answers 2

up vote 3 down vote accepted

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
share|improve this answer
    
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 '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 2 '11 at 6:44
    
@Sirex: in addition to unixtippse's list there's 'popd' and others. –  symcbean Sep 5 '11 at 9:49

You could write a script inside .bashrc

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.