PDA

View Full Version : Permissions problem


webwizzy
4th March 2009, 09:21
Hello,

1. All my folders are saving as 0775 by default, whereas they should be 0755 right?

Similarly, all my PHP files save as 0664 by default, instead of 0644.

How do I correct this problem?

2. Another thing is that:-

My folder structure is like this: /home/username/public_html

/home/ is owned by root and is chmod 0755
/username/ is owned by username and is chmod 0755
/public_html/ is owned by username and is chmod 0755

Are these permissions good? I mean are they secure enough?

Thanks

falko
5th March 2009, 18:32
[QUOTE=webwizzy;173139]Hello,

1. All my folders are saving as 0775 by default, whereas they should be 0755 right?

Similarly, all my PHP files save as 0664 by default, instead of 0644.

How do I correct this problem?
/QUOTE]
Are you talking about FTP? If so, what FTP server are you using?

webwizzy
5th March 2009, 18:57
I am using just SFTP, and WinSCP as my SFTP client.

I also tried creating a new php file from SSH while logged in as "username".

It is giving 0664 to php files by default, instead of 0644. What should i do?

Thanks

webwizzy
5th March 2009, 20:18
okay.. I found one thing.

I notice that when I upload files from "username", only then 0664 and 0775 permissions are being given. However, this is not happening with "root". The file/folder permissions are correct if uploaded from root account.

What should I do to make "username" upload files/folders as 0644 and 0755?

And why did this happen when I simply created user like useradd username , it should have inherited default permissions, right?

Thanks

webwizzy
6th March 2009, 04:23
OKAY.. I solved this problem after some crazy googling. I am sure someone setting up servers from scratch can face this problem too, so here's the solution.

1. Connect to SSH as username.

2. Edit the bashrc file:

vi .bashrc //this file resides in /home/username folder3. Add the following at the end of the file:

umask 022Save and close the file. Changes will take effect after next login. Thats it! :)

Problem Description:-

- The default umask 002 is used for normal user. With this mask, default directory permissions are 775 and default file permissions are 664. (This was the problem in my case)

- The default umask for the root user is 022. With this mask, default directory permissions are 755 and default file permissions are 644. (Which I want for my username too)

- For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-rw).

To calculate directory permission for 022:
Default Permissions: 777
Subtract umask value: 022 (-)
Allowed Permissions: 755

To calculate file permission for 022:
Default Permissions: 666
Subtract umask value: 022 (-)
Allowed Permissions: 644


Thanks