Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1014
  • Last Modified:

How can you set Default Permissions for a specific directory using Linux (Ubuntu)?

I'm having trouble with default file/directory permissions using Linux. I know that the default is 0022, and you can change it using umask.

When I create a file, 0022 gives me:

-rw-r--r--

What I want is:

-rwxr-xr-x

Directories work. They show up as:

drwxr-xr-x

Using FileZilla (FTP client), if I right-click an item and change the permissions to "755", I get the desired effect. However, if I try "umask 755" in Linux, I get the following after creating a file via VI:

-----w--w-

And directories start showing up as:

d----w--w-

In the end, I just want all of the sub-folders in /var/www/ to be the only directories with these permissions, and I'd like to keep the root default to 0022. Can someone assist?

Thank you!
0
christophertate
Asked:
christophertate
3 Solutions
 
amit_gCommented:
The umask is opposit of permssions i.e. the umasked permissions are taken away. The lowest umask you can set is 0000 and that would result in -rw-rw-rw- for the files and -rwxrwxrwx for the directories. The max permissions for file is 666 and for directories is 777. So with umask you can't create a file with 755 (-rwxr-xr-x).
0
 
Pétur Ingi EgilssonSoftware Engineer -- ConsultantCommented:

umask works as follows
Directories will be created with the umask subtracted from 0777
HOWEVER, files will be created with the umask subtracted from 0666
 
Thus if you umask 0222 files will be created with r--r--r-- (0444) while directories will be created with dr-xr-x-r-x (0555)
 
umask 0022 should work fine for you.

Open in new window

0
 
christophertateAuthor Commented:
So files don't use the execute flag at all?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TintinCommented:
Files use execute permissions, but as already explained, umask can not be used to create a file with execute permission.


0
 
Pétur Ingi EgilssonSoftware Engineer -- ConsultantCommented:

You won't need to set the execute bit on files unless they are binaries to be executed on the system itself ( programs) 

Open in new window

0
 
amit_gCommented:
Basically you can't create a executable file by default (by setting umask) i.e. you need to make a file executable explicitly.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now