Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Hay, i have some files on my server with the owner set to "apache", I'm not quite sure how this happened.

Anyway, i need to change the permission of these files to 0777 so i can download/edit them. However i cannot.

I'm using a 1and1 Linux server and use Plesk to administrate it.

I have the ability to login via SSH. However, if i run chmod or chown i get a "permission denied" error, and if i try to sudo chmod or chown it says the command cannot be found.

When i go to edit my domain details, i get this option

Shell access to server with FTP user's credentials

and have these options

/bin/sh
/bin/bash
/sbin/nologin
/bin/bash (chrooted)
/bin/rbash

Any idea's how i should go about changing the permissions or changing the owner?

Thanks

share|improve this question
    
Why do you want to change their positions? If they are used by the Apache, then Apache is most likely the owner you want it to have. Is their a specific reason you want to change the files owner? –  Dan McGrath Jul 23 '10 at 8:27
    
They are images, i want to be able to download them from my FTP server. But i always get permission denied. –  Dotty Jul 23 '10 at 8:58

3 Answers 3

up vote 2 down vote accepted

Use php's chmod function.

<?php
chmod("/somedir/somefile", 0777);
?>

also you can also use shell_exec function

<?php
echo shell_exec("chmod 777 /somedir/somefile");
?>
share|improve this answer
1  
chmod works fine, chown doesn't. –  Dotty Jul 23 '10 at 10:02

you need to be root the change the owner of "foreign" files. If you not able to gain root access you could try to change the permissions of the files via php.

Try to run the php script in your browser, the owner of the script should be the apache user.

share|improve this answer
    
I made a simple script called fix.php and wrote "print system('whoami')" and it returns "apache". I then used chmod() and managed to change the permission, however i still cannot do anything with the files, chown() always fails. –  Dotty Jul 23 '10 at 8:35
    
Not all users can automatically change the ownership of even files they own, because there are ways that ability could be twisted into a security risk. I remember reading something about that recently (possibly right here on SF) but I can't remember/find the link... maybe someone else can provide more details. –  David Z Jul 23 '10 at 8:50
    
are you able to read the files? you could read them all and download them with you browser. David is right about the possible security risk but I cant remember the scenario and details –  krissi Jul 23 '10 at 9:25
    
I am able to read the files, i can open them in a browser. This seems the way i will have work. –  Dotty Jul 23 '10 at 10:02
    
david: if somebody set the setuid bit on a file, then gave it away, then ran it it would run as the other user. also, it might count towards the other user's disk quota –  immibis Dec 26 '10 at 13:04

This might be a stupid question, but did you try su? I assume you have full control over the server (it's not a shared web host or something) because they wouldn't put everyone's files under the same user "apache"

share|improve this answer

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.