Search code examples
permissionsrpmumask

How do you change the umask when building with rpmbuild?


I've tried 'umask 77' in the shell, then building it with:

[non-root-user@machine SPECS]$ rpmbuild -bb SPECFILE.spec 

but I still get this from the output:

+ umask 022 

Solution

  • You cannot change the umask from the shell because rpmbuild will always set a a fixed umask of 0022 before running %prep script.

    Therefore, depending on what you're trying to achieve, you could try change the umask in the spec file, at the beginning the %prep section:

    %prep
    umask 077
    

    But, if you're just trying to set the file permissions for the files in the RPM, the standard way is to use %defattr and %attr directives in the %files section:

    • %defattr sets the default attributes for files and folders:

      %defattr(<file mode>, <user>, <group>, <dir mode>)
      

    some attributes may be omitted by replacing them with a dash (because the file is installed with those attributes properly set)

    • %attr sets the attributes for a single file or folder:

      %attr(<mode>, <user>, <group>) file/folder
      

    As with %defattr if a particular attribute does not need to be specified, you can replace it with a dash (for example you can use it along with %defattr to keep the default value for that attribute)

    A full example:

    %files
    # set default attributes for all files and folders:
    %defattr(644, root, root, 755)
    # make a file executable:
    %attr(755, -, -) /usr/bin/myexec
    # set a different owner for a file:
    %attr(-, myuser, -) /var/log/mylog.log
    # set different permissions, owner and group for a file:
    %attr(600, myuser, mygroup) /home/myfile
    

    For more details & examples you can take a look to:
    http://www.rpm.org/max-rpm-snapshot/s1-rpm-specref-files-list-directives.html and
    http://www.rpm.org/max-rpm/s1-rpm-anywhere-specifying-file-attributes.html