Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With Natty coming out soon, I've been at work updating my deployment and self-config script to make my desktop on 11.04 run and look the way I want it to.

One bummer is that dbus seems to have changed and does not permit, in the same manner Lucid and Maverick did, the authentication of the current user by terminal call using grep and cat.

Ideally, to run the script, I would sudo -s and then launch it as

# chmod +x install && ./install

Instead of returning my user name.. it now returns root and applies changes to the root profile and aborts whenever paths do not correspond.

Here is my script header:


ON_USER=$(echo ~ | awk -F'/' '{ print $1 $2 $3 }' | sed 's/home//g')

export $(grep -v "^#" ~/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0)

if sudo -u $ON_USER test -z "$DBUS_SESSION_BUS_ADDRESS" ;
then eval `sudo -u $ON_USER dbus-launch --sh-syntax --exit-with-session`

RELEASE=$(lsb_release -cs)

How could I make it return the actual user now that natty is coming?

Thanks for the help

share|improve this question

It sounds like $HOME is being changed to /root within your script's environment. Try using $SUDO_USER instead of $ON_USER, and $(eval echo ~$SUDO_USER) instead of ~:

ak@myo5a:~$ echo "$(grep -v "^#" ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0)"
ak@myo5a:~$ sudo -sH
root@myo5a:/home/ak# echo "USER=$USER; HOME=$HOME; SUDO_USER=$SUDO_USER; SUDO_HOME=$(eval echo ~$SUDO_USER)"
USER=root; HOME=/root; SUDO_USER=ak; SUDO_HOME=/home/ak
root@myo5a:/home/ak# echo "$(grep -v "^#" $(eval echo ~$SUDO_USER)/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0)"
root@myo5a:/home/ak# sudo -u $SUDO_USER touch /cant_touch_this
touch: cannot touch `/cant_touch_this': Permission denied
share|improve this answer
doesn't work as I need it to grand system modification access and specific USER case application for given folders and configs. SUDO_USER still only returns root... – user12213 Mar 12 '11 at 2:19
What user are you running sudo -s as? – ændrük Mar 12 '11 at 4:21
@Cypher2 My example is consistent with the design of sudo and Ubuntu's default file permissions. The sudo manual explains that "The -u option causes sudo to run the specified command as a user other than root." Running a command via sudo -u $USER is the same thing as running the command as the user $USER. Thus, you should not expect to have any elevated privileges when using sudo -u $SUDO_USER unless sudo -s was originally run as root. – ændrük Mar 12 '11 at 21:49

Your Answer


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