Solved

default permissions assigned by cp command in Unix

Posted on 2014-04-16
12
684 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Accepted Solution

by:
Rok Brnot earned 350 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 150 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access_log 17 151
aix unix tar error 3 73
awk sed 8 68
remove one line from a file in solaris 8 43
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

821 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