Newbie question 777 on directory or just file?

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
zenkert
Forum Newbie
Posts: 3
Joined: Thu Nov 06, 2008 7:45 am

Newbie question 777 on directory or just file?

Post by zenkert »

Hi,

This is a real newbie question I guess.
I need to have read and write permission - 777 - on just one single file in a directory.
Is it enough to set 777 on just the file?
Or do I have to set it on the whole directory?

(PS the directory and the file are already in a password protected area of the site)

Zenkert
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Newbie question 777 on directory or just file?

Post by VladSun »

Code: Select all

vladsun@designer:~$ mkdir dir
vladsun@designer:~$ touch dir/file
vladsun@designer:~$ ls -lR
.:
total 8
-rwx------ 1 root    root     678 2008-09-13 21:40 db_check
drwxr-xr-x 2 vladsun vladsun 4096 2008-11-06 16:10 dir
 
./dir:
total 0
-rw-r--r-- 1 vladsun vladsun 0 2008-11-06 16:10 file
vladsun@designer:~$ chmod 000 dir
vladsun@designer:~$ cd dir/
bash: cd: dir/: Permission denied
vladsun@designer:~$ chmod 100 dir
vladsun@designer:~$ cd dir/
vladsun@designer:~/dir$ cd ..
vladsun@designer:~$ ls dir/
ls: dir/: Permission denied
vladsun@designer:~$ chmod 500 dir
vladsun@designer:~$ ls dir/
file
vladsun@designer:~$ touch dir/file2
touch: cannot touch `dir/file2': Permission denied
vladsun@designer:~$ chmod 700 dir
vladsun@designer:~$ touch dir/file2
vladsun@designer:~$ ls dir/
file  file2
vladsun@designer:~$
 
...

Code: Select all

vladsun@designer:~$ chmod 500 dir
vladsun@designer:~$ echo "Example" > dir/file2
vladsun@designer:~$ cat dir/file2
Example
vladsun@designer:~$ ls -l dir/file2
-rw-r--r-- 1 vladsun vladsun 8 2008-11-06 16:13 dir/file2
vladsun@designer:~$ rm dir/*
rm: cannot remove `dir/file': Permission denied
rm: cannot remove `dir/file2': Permission denied
vladsun@designer:~$ chmod 700 dir
vladsun@designer:~$ rm dir/*
vladsun@designer:~$ ls dir/
vladsun@designer:~$
There are 10 types of people in this world, those who understand binary and those who don't
zenkert
Forum Newbie
Posts: 3
Joined: Thu Nov 06, 2008 7:45 am

Re: Newbie question 777 on directory or just file?

Post by zenkert »

Vladsun, I do not understand your answer.
My site is on adminstaited by me on cPanel.
So I guess I just have to alter the permisson to the directory or the file or both?

Zenkert
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Newbie question 777 on directory or just file?

Post by VladSun »

I think my post is more than an answer to your question - you have to understand what I've shown and you will get your particular answer.

Also, why don't you just try what you are asking? Starting with the file, then directory, then both. The first one to work is your solution ;)
There are 10 types of people in this world, those who understand binary and those who don't
zenkert
Forum Newbie
Posts: 3
Joined: Thu Nov 06, 2008 7:45 am

Re: Newbie question 777 on directory or just file?

Post by zenkert »

You´re one "h..." of a guy :lol:
Real hard coder I guess :D

Anyway, after your first answer I´ve tried and both solutions work.
I went for setting 777 to the file, since that for me seemed more secure.

But I have to say - to understand what you wrote in the first answer I have to study hard.
REAL HARD :D
Post Reply