Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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!

share|improve this question
add comment

8 Answers

up vote 4 down vote accepted

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
share|improve this answer
    
thanks! it just worked. and your explanation of why this would work, was very helpful. as this solved my problem but i'm still curious to know how can i open krusader as another user. other solutions just did not work. –  takpar Oct 13 '10 at 16:10
add comment

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.

share|improve this answer
    
thanks, but it returns: No protocol specifiedkrusader: cannot connect to X server :0.0 –  takpar Oct 10 '10 at 7:04
1  
before launch gksudo command, in terminal under your account run: xhost + –  jet Jan 28 '11 at 14:29
add comment

Like Marco mentioned you can use gksudo -u www-data <command> to run commands as another user. I routinely use this to run commands as gdm and so far it has never asked me for anything other than my own password.

If you are using kde the equivalent is kdesu -u www-data krusader.I think, since krusader is a kde application, it might work better with kdesu. More details about kdesu here.

I have used gksudo to run commands as other "human" users on the system and when I am prompted for password, I type in mine.

share|improve this answer
    
thanks, but result is as gksudo: No protocol specifiedkrusader: cannot connect to X server :0.0 –  takpar Oct 10 '10 at 7:05
    
Probably for krusader (a kde app), kdesu is a better choice. I have updated my answer. Can you try that ? –  koushik Oct 10 '10 at 14:30
    
+1 for introduction to kdesu; and i'll try it –  takpar Oct 10 '10 at 17:52
add comment
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.

share|improve this answer
add comment

To become www-data with your own password, use this:

$ sudo su www-data
[sudo] password for <your username>: [enter your password]
$ whoami
(you should see www-data here)

But, I don't think you'll be able to run GUI apps from there..

I usually just own everything in /var/www, but allow read access to everyone:

/var/www$ sudo chown -R [your-username]\:[your-group] *
/var/www$ find . -type d -exec chmod a+rx {} \;
/var/www$ find . -type f -exec chmod a+r {} \;

I hope that will ease your pain :)

share|improve this answer
    
as you guessed i couldn't run GUI apps from there. it sayed No protocol specified krusader: cannot connect to X server :0.0 –  takpar Oct 11 '10 at 13:10
    
Is the second solution not an option for you? You data does not have to be owned by www-data, although I guess it's preferred. –  dr Hannibal Lecter Oct 11 '10 at 15:01
add comment

I believe you need to run the following at the terminal:

xhost +SI:localuser:<user-to-run-as>

Then you can do:

sudo su - <user-to-run-as>

And lastly, run your app:

krusader

That should do it, just be sure to replace <user-to-run-as> with your username of course.

share|improve this answer
add comment

Both 'gksu' and 'kdesu' are graphical frontends for 'sudo', which is the tool you should use when you're in a text-only environment. The 'gksu' and 'kdesu' tools require you to be in a graphical mode, that explains the "cannot connect to X server" errors.

if you want to execute a console command as a different user you use the command 'sudo -u username command'.

share|improve this answer
    
thanks, i run that and it says something like [1] 12100 that seems to be the process id; but nothing i see in action. –  takpar Oct 10 '10 at 17:49
add comment

Running a graphical application under www-data gives you several problems. A thing you can do is adding yourself to the www-data group, so you'll be able to change all the files you need:

sudo adduser $USER www-data

Note: probably, you'll need to log out from the session for the change to take effect.

If, after this command, you are still unable to change some files, just ensure that you have write permission on them:

sudo chown www-data:www-data /var/www/file
chmod g+w /var/www/file
share|improve this answer
    
however it isn't a solution for the general problem but it seems to work for my case; i'll give it a try and report –  takpar Oct 10 '10 at 17: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.