Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In most Linux distros I've used when you type for example ifconfig as a normal user, you get a prompt message telling you that only root can execute such command.

In Debian, it only says command not found (because it's looking for it in /usr/bin/).

I'm wondering if there is any way for prompt a message, like "ifconfig must be run as root" or something like that.

share|improve this question
5  
You should be able to execute ifconfig as a regular user. I have never seen ifconfig issuing such a prompt message in its default capacity. –  Chris Down Dec 9 '12 at 17:44
    
70% of the commands in */sbin don't need superuser privilege. If a command needs superuser priviledge, it will tell you. It's safer not to run a command as root, so I'd rather issue the opposite warning like beware, this is run as root when not needed. –  Stephane Chazelas Dec 9 '12 at 19:14
add comment

2 Answers

In Debian, it only says command not found (because it's looking for it in /usr/bin/)

That just means your non-root users don't have /sbin in their PATH. Run /sbin/ifconfig explicitly and see what it says when you aren't root.

If the message is ok, you just need to add /sbin to your PATH.

share|improve this answer
add comment

You can do it like this :

trap '
    if [[ $BASH_COMMAND =~ /sbin ]] && ((UID!=0)); then
        echo >&2 "${BASH_COMMAND##*/sbin/} must be run as root"
    fi
' DEBUG

But ifconfig is accessible for users too, just need to type /sbin/ifconfig.

Like Chris Down said, I have never seen ifconfig issuing such a prompt message in its default capacity.

share|improve this answer
    
+1 for telling me about =~ BASH_COMMAND and DEBUG in one post. But this solution will only work if the sbin folders are in path and the binary is actually about to be exectuted, won't it. This already implies execute rights for non root user which does semantically collide with the intention and error message. But I'm just trying to be smart :-) –  Bananguin Dec 9 '12 at 19:11
    
yep, seem it was a problem of PATH. Btw, where should I write that? I tried in .bashrc but nothing changed. –  yzT Dec 9 '12 at 20:54
    
Did you source your .bashrc or close and open a new terminal? –  laebshade Dec 9 '12 at 21:51
add comment

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.