2

On opening a new xterminal or starting bash in an already running bash, I get a surprising error message 2 times:

t201:~ > bash
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Since I don't invoke bash with sudo, I ask myself, where this might come from.

First suspect is of course ~/.bashrc, where I often add small functions, but grep su ~/.bashrc only reveals words containing 'su' like success and support, all of them in comments.

So I used bash -v to invoke bash in a verbose fashion.

This showed me a lot of commands, directly or indirectly triggered from .bashrc, and between the lines this:

# sudo hint
if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; then
    case " $(groups) " in *\ admin\ *|*\ sudo\ *)
    if [ -x /usr/bin/sudo ]; then
    cat <<-EOF
    To run a command as administrator (user "root"), use "sudo <command>".
    See "man sudo_root" for details.

    EOF
    fi
    esac
fi
groups
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

except from the 3 lines after fi, this is found in /etc/bash.bashrc

Ok. That's looking for a magic file .sudo_as_admin_successful . I remembered a command

 find -empty -delete 

Issued few hours ago, but in the home directory, not where it should have been issued, but empty files - who cares?

Well, now I care.

I created a new one:

t201:~ > touch .sudo_as_admin_successful 
t201:~ > bash
t201:~ > 

Error is gone. Do I need special permissions on that file? And what is .hushlogin? I don't have this either.

2

1 Answer 1

1

~/.sudo_as_admin_successful is an example of a "flag file", where the existence of the file is important, not the content. You'll notice, in the script fragment, that:

  • If ~/.sudo_as_admin_successful exists, (really, "NOT exists" is FALSE) the whole thing is skipped.
  • ~/.hushlogin is another "flag file", whose existence requests login scripts to be extra quiet. It's left over from early days, but, when set by the user, makes the request.
  • Then, using the groups command to list $USER's groups (try it - type groups), check if $USER is a member of the admin or sudo groups.
  • Finally, check for an executable /usr/bin/sudo.
  • Then, if all this is true, issue the hint.

~/.sudo_as_admin_successful is set by /usr/bin/sudo when you successfully switch to UID 0. Verify: sudo strings /usr/bin/sudo | grep ".sudo_as_admin_successful").

Modern system administration practice would have the file elsewhere, but sudo is old (not obsolete), and is developed outside Canonical/Ubuntu. There are pros and cons to moving ~/.sudo_as_admin_successful. sudo is used on all sorts of Linux and Unix systems. It's necessary for it to be compatible with ALL of them, so ~/.sudo_as_admin_successful is the simplest choice.

You must log in to answer this question.

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