|
OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
Understanding umask
Code:
$ umask 026 $ umask -S u=rwx,g=rx,o=x $ touch foo $ ls -l foo -rw-r----- Code:
-rwxr-x--x |
|
|||
Wikipedia has a quite good entry about it: https://en.wikipedia.org/wiki/Umask
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
While we're on topic, is there a way to set the umask for a process? Say my default umask is 022 and I'm creating a file in ed for example or with echo and want it to be written to disk with 077 just for this process (incl. any temporary files that might be created)?
|
|
||||
This may not be exactly what you want, but you could run it in a sub-shell; e.g.,
% ( umask 0777 ; echo FOO > foooo ) will take away all the usual permissions from the file, while leaving the outer umask unchanged. |
|
|||
Shell scripts are usually run as a separate process.
You can set the umask in a shell script so it will only affect the file creating commands of that script. After the script has ended the umask value of your interactive shell will still be the original. Code:
#!/bin/sh FILE=umask_test [ -f $FILE ] && rm $FILE cat <<END Current value of umask: $( umask ) END umask 066 cat <<END Current value of umask: $( umask ) END echo Creating file touch $FILE ls -l $FILE echo End of script ..... Code:
j65nko@alix[~]./umask.tst Current value of umask: 022 Current value of umask: 066 Creating file -rw------- 1 j65nko j65nko 0 Oct 30 22:11 umask_test End of script ..... j65nko@alix[~]umask 022 j65nko@alix[~]
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
Quote:
Code:
$ cat test.sh ( umask u-w,g-rx,o-rx ; ed <<- EOF H a # By order of the Peaky fookin' Blinders! . w foooo q EOF ) touch baaaar $ umask 022 $ ls -al foooo baaaar ls: baaaar: No such file or directory ls: foooo: No such file or directory $ ./test.sh 42 $ ls -al foooo baaaar -rw-r--r-- 1 fvgit fvgit 0 Oct 30 22:12 baaaar -r-------- 1 fvgit fvgit 42 Oct 30 22:12 foooo |
|
||||
@J65enko: My use case was actually a single command from within a larger script. So that that single cmd would have a different umask applied than the remaining commands in the same script. I thought about setting the umask, then running the command and setting the umask again, originally. But I didn't find it really elegant.
Quote:
I'm adding both your and IdOp's examples to my toolchest. |
|
|||
This script will show permissions based on current value of umask:
Code:
#!/bin/ksh typeset -i2 defa typeset -i onescomp (( onescomp=~(8#$(umask)) )) (( defa=(8#666)&onescomp )) defaultPerm=${defa#*#} print "\nDefault regular file permissions with current umask ($(umask))" print " u g o" print "_________" print "rwxrwxrwx" print $defaultPerm print "\nDefault directory file permissions with current umask ($(umask))" typeset -i2 ddefa (( ddefa=(8#777)&onescomp )) defaultPerm=${ddefa#*#} print " u g o" print '_________' print 'rwxrwxrwx' print $defaultPerm print "\n1s are on, 0s are off\n" Code:
$ chmod u+x ~/permissions ~/permissions umask 027 ~/permissions |
|
|||
If a file has permissions rw--------- und I create a link to it with ln -s, the link has permissions of lrwxr-xr-x. How can I change link's permissions to be lrw--------- ?
|
|
|||
I found how to do it. chmod -h 600 link
|
Tags |
umask |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Understanding relayd | sleepyjoe | OpenBSD Security | 2 | 26th April 2020 05:30 AM |
understanding tcpdump | frcc | OpenBSD Security | 3 | 11th April 2013 10:10 PM |
Understanding and Community | Ninguem | Off-Topic | 4 | 31st March 2012 01:22 AM |
Help needed with understanding PF rules | sparky | OpenBSD Security | 7 | 26th March 2012 09:07 PM |
Understanding the FreeBSD kernel | TomAmundsen | FreeBSD General | 3 | 7th July 2008 02:48 PM |