How to run an Application as another user?
I use krusader for file management stuff. the problem is that apache's DocumentRoot
should be under chown www-data:www-data /path/to/www
. so using krusader (which is run under my account) I've not write access to /path/to/www
while I really need. I don't know how other developers can continue doing things with such a restriction!
I wondered if I could run krusader as www-data
then I will be able to easily play with files. but using su - www-data
asked me for www-data
's password!!
So, how can I run an application (like krusader) as another user (like www-data) in Gnome?
or is there any other solution for my case? (tough I'm really curious to know the answer!)
keep in mind that I know I can run it as root! but this will cause some permission problems when using cp
and mkdir
, you know.
PS:
sudo
and gksudo
did not help:
$ gksudo -u -www-data krusader
No protocol specified
krusader: cannot connect to X server :0.0
Final Note:
according the best answer, i did chmod u+w /path/to/www
and my problem solved. but i still has not been succeeded in opening krusader as another user!
Solution 1:
xhost +SI:localuser:uname
gksudo -u uname -l "firefox"
xhost -SI:localuser:uname
Where uname = the name of impersonated user. Seen there: http://ubuntuforums.org/showthread.php?p=10399617
Works on my maverick box, there's no sound in the forked skype and ~/.profile.d is not executed as it might.
Solution 2:
If you're running this from the menu system you'll want to use alacarte
(System > Preferences > Main Menu) and change the entry for krusader and add in front of it: gksudo -u www-data
which should produce something like:
gksudo -u www-data krusader
This will launch the administrative task prompt window which, according to the GKSudo Manpage, is a
GTK+ Frontend for su and sudo
Using just gksudo without the -u
switch will run the command as root.
Solution 3:
Rethinking about this question (I hope to have understood your problem right, but correct me if I'm wrong), I found an another solution and I think you don't need to run the application as www-data nor to play with permissions. You said that:
Apache's DocumentRoot should be under chown www-data:www-data /path/to/www
but actually, this isn't fully true: Apache's DocumentRoot
must be readable by www-data
, but not necessarily owned by it. By default, in Ubuntu Desktop, all files and directories you create are readable by everybody, so you can set your DocumentRoot to a directory inside your home folder, for example:
DocumentRoot /home/user/my-project/my-document-root