Solved

default permissions assigned by cp command in Unix

Posted on 2014-04-16
12
676 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
 
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 37

Expert Comment

by:Gerwin Jansen
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 37

Expert Comment

by:Gerwin Jansen
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 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
removing nim resources 5 48
Where to get php 5.6 for AIX 7.1? 5 82
Unix How to Bulk Remove Multiple Directories from FileSystem 10 76
Access_log 17 101
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now