分类:
2011-03-02 11:26:25
When you su to root from a terminal where you are logged in as another user the new "su-ed" user gonna inherit the environment variables from the parent shell user.
Example: let's say that for the user jack the DBUS_SESSION_
Now if you open a terminal as jack and make a su to root the DBUS_SESSION_
as for the user jack. And here is the problem, exactly this specific env. variable (DBUS_SESSION_
Gnome programs like gedit, nautilus . . . use the dbus protocol to
communicate with gconf where application specific configurations are
stored, and not just.
A program executed as root uses a different D-Bus session bus address
compared when you execute that program as the jack user for instance. So
the problem is that you switch to root, but the DBUS_SESSION_
Solution:
The root user has a separate dbus session address too (located in /root/.
So to use the root's dbus address when you are in a terminal and "su-ed" to root just clear the DBUS_SESSION_
A program that needs dbus communication with gconf for instance, checks
that environment variable, and if it is empty it reads the dbus address
from the users ~/.dbus/
To make this permanent add the following line to the root users .bashrc file:
export DBUS_SESSION_
This means that every time when you su to root and the terminal is not a
login shell (the case when you are logged in as jack and opened a
terminal and executed su) the DBUS_SESSION_
by the way you do not need to start a new dbus session with dbus-launch. Even if you do so but the applications still read the dbus address from the wrong place, the problem will persist.
就是在管理员用户的 .bashrc 文件尾部添加:
export DBUS_SESSION_BUS_ADDRESS=
例如,编辑 /root/.bashrc 文件,添加一行 export DBUS_SESSION_BUS_ADDRESS=“”
另外就是使用 su - root 代替su,sudo
其区别是su sudo 使用当前用户的环境变量,su - root会使用root用户的环境变量。
另外一个: