mogrify is not preserving file permissions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hei
Posts: 2
Joined: 2016-02-06T17:47:45-07:00
Authentication code: 1151

mogrify is not preserving file permissions

Post by hei »

Hi,

I'm using mogrify to crop images. These images are located in /tmp directory. Before using mogrify images have file permissions 600. After using mogrify file permissions changed to 644. This is a serious problem for me because now the images are world readable and I'm on a shared system.

Is this behaviour intended? How can I preserve file permissions?

More informations below:

Code: Select all

vagrant@vagrant-ubuntu-trusty-64:/vagrant$ mogrify --version
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

vagrant@vagrant-ubuntu-trusty-64:/vagrant$ chmod 600 red10x10.png
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ stat red10x10.png
  File: ‘red10x10.png’
  Size: 318       	Blocks: 8          IO Block: 4096   regular file
Device: 19h/25d	Inode: 3371        Links: 1
Access: (0600/-rw-------)  Uid: ( 1000/ vagrant)   Gid: ( 1000/ vagrant)
Access: 2016-02-07 13:42:54.000000000 +0100
Modify: 2016-02-07 13:42:54.000000000 +0100
Change: 2016-02-07 13:45:06.000000000 +0100
 Birth: -
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ mogrify -crop 10x10+0+0 red10x10.png
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ stat red10x10.png
  File: ‘red10x10.png’
  Size: 318       	Blocks: 8          IO Block: 4096   regular file
Device: 19h/25d	Inode: 3372        Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/ vagrant)   Gid: ( 1000/ vagrant)
Access: 2016-02-07 13:45:13.000000000 +0100
Modify: 2016-02-07 13:45:13.000000000 +0100
Change: 2016-02-07 13:45:13.000000000 +0100
 Birth: -
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: mogrify is not preserving file permissions

Post by glennrp »

You could run "umask 0077" before running "mogrify".
hei
Posts: 2
Joined: 2016-02-06T17:47:45-07:00
Authentication code: 1151

Re: mogrify is not preserving file permissions

Post by hei »

Thanks, that helped!
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: mogrify is not preserving file permissions

Post by glennrp »

In fact, when running on a shared system, it might be a good idea to put the "umask 0077" in your .profile so that by default any file you write with any application will only be accessible to you, and you don't need to worry about forgetting to protect it.
Post Reply