I see there is a question similar to this but that answer relates to Git, which I am not using here.

I often make small scripts that I send to others with very limited command-line skills to run. Is there a way to package my script so that users don't need to change permissions for my executable? I tried to package my script such that the first executable script changes the permissions for all the others, but at this point I have been unable to find a way to ship that first script in a way such that the user does not have to give it execute permission i.e. chmod +x First_script

Am I running into this wall because there is no solution?

  • Is it an option to give it to them as a tar or some other archive? That would preserve your permissions when they extract the files. Commented Sep 25, 2019 at 18:11

3 Answers 3


A simple way is to make a tarball, a compressed tar archive. It you create it with root privileges and the user extracts the content also with root access, the permissions should be preserved.


sudo -cvzf filename.tar.gz directory  # create a compressed tar archive of the directory and its content

cd /to-where-you-want-it-extracted
sudo -xvzf filename.tar.gz            # extract the content from the archive

There are details in man tar and you find good tutorials about tar via the internet.

  • Ahh so the tradeoff is 'user knows how to de-compress tarball' vs. 'user knows how to recognize when permissions need to be changed and change them'
    – gracie
    Commented Sep 25, 2019 at 18:37
  • 1
    I think zip can also preserve permissions in Linux. I think most people are fairly familiar with zip archives and can extract them via some sort of GUI without having to touch the terminal. Commented Sep 25, 2019 at 18:48
  • 1
    @gracie, Most Linux archive tools in with a graphical user interface, for example file-roller, can do the extraction automatically (both from zip archives and tarballs). So there need not be a tradeoff.
    – sudodus
    Commented Sep 25, 2019 at 19:01

You can wrap your script (that has executable rights at this point) into the package format for the OS in question.

Then your users can just install the package and the proper rights will automatically be there.

debreate is an easy solution for this very problem on debian-based OSes.


The shar command, see man shar, was invented to do just this type of thing.

From man shar, or https://manpages.ubuntu.com/manpages/bionic/en/man1/shar.1.html


   shar creates "shell archives" (or shar files) which are in text format and can be emailed.
   These  files  may be unpacked later by executing them with /bin/sh.  The resulting archive
   is sent to standard out unless the -o option is given.  A wide range of  features  provide
   extensive flexibility in manufacturing shars and in specifying shar "smartness".  Archives
   may be fairly simple (--vanilla-operation) or essentially a mailable tar archive.



   The first shows how to make a shell archive out of all C program sources.  The second
   produces a shell archive with all .c and .h files, which unpacks silently.  The third
   gives a shell archive of all uuencoded .arc files, into numbered files starting from
   arc.sh.01.  The last example gives a shell archive which will use only the file names at
   unpack time.

       shar *.c > cprog.shar
       shar -Q *.[ch] > cprog.shar
       shar -B -l28 -oarc.sh *.arc
       shar -f /lcl/src/u*.c > u.sh
  • A quick example would go a long way towards showing how it would solve the problem.
    – Jeff Schaller
    Commented Sep 26, 2019 at 0:27
  • @jeff-schaller Reading the man page would go all the way.
    – waltinator
    Commented Sep 26, 2019 at 3:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .