Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

default permissions assigned by cp command in Unix

Posted on 2014-04-16
12
Medium Priority
?
730 Views
Last Modified: 2014-04-18
Hi,

What is the default permissions mask when using the cp command in Unix?  it appears to be 644.  I would like to have it be 770.  Umask won't help in this instance as it only takes away permissions, it doesn't add them, apparently?  Is there another way to get that done w/o having to chmod every copied file?

Thanks!

--Ben
0
Comment
Question by:Ben Conner
  • 7
  • 3
  • 2
12 Comments
 
LVL 5

Expert Comment

by:Rok Brnot
ID: 40004538
cp -p will preserve permissions, so if original permissions are 770...
0
 

Author Comment

by:Ben Conner
ID: 40004551
Ah.  That explains a lot. :)  What about when creating a file from scratch?

--Ben
0
 

Author Comment

by:Ben Conner
ID: 40004553
If I wasn't using the -p argument, what would cp do?  This was in a script I had run.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Accepted Solution

by:
Rok Brnot earned 1400 total points
ID: 40004614
In the absence of this option (-p), the permissions of existing destination files are unchanged, while each new file is created with the mode bits of the corresponding source file, minus the bits set in the umask and minus the set-user-ID and set-group-ID bits.
0
 

Author Comment

by:Ben Conner
ID: 40004658
Ah.  So there are default permissions masks associated with individual userids and groups?  That is probably what the root cause of this is, then.  Is there a non-su command available to change that default?
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40005376
The directory you are copying into probably has rw-r--r-- (644) security set. Files created (cp without -p) in there will have those as well. Changing that directory to rwxrwx--- will give you your default of 770 (again without umask).
0
 

Author Comment

by:Ben Conner
ID: 40005433
Hm.  Just checked and all the target folders had 770 assigned.  Is there a default security setting assigned when an account is set up?  Never been an admin so I wouldn't know.  They don't give me sharp objects.

--Ben
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40005952
That would be the umask. Can you check umask? Just type umask to display the current.
0
 

Author Comment

by:Ben Conner
ID: 40006405
Hi Gerwin,

Thanks, will look at that when I get in to work in a little while.  I guess though I was trying to confirm that while setting up a userid for the first time, there is a spot where the admin sets this for that account as a default?

--Ben
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 600 total points
ID: 40006847
Yes, it is set at /etc/profile for example on RHEL:

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
    umask 002
else
    umask 022
fi
0
 

Author Comment

by:Ben Conner
ID: 40006916
That nails it.  So my assumption is if an admin can create it, they can modify it.  That would save us a lot of hassle.

Thanks much!!

--Ben
0
 

Author Closing Comment

by:Ben Conner
ID: 40009997
Excellent insight on an area that isn't very well documented in common references.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question