差分

移動先: 案内検索

ユーザ権限とアクセス制御

435 バイト追加, 2017年2月3日 (金) 17:37
<pre classsyntaxhighlight lang="bash">
$ ls -l memo.txt
-rw-r--r-- 1 hironobu hironobu 44 Sep 20 19:17 memo.txt
$ ls -l /var/mail/hironobu
-rw-rw---- 1 hironobu mail 0 Dec 9 19:39 hironobu
</presyntaxhighlight
<pre classsyntaxhighlight lang="bash">
$ chmod go-rw memo.txt
$ ls -l memo.txt
-rw------- 1 hironobu hironobu 44 Sep 20 19:17 memo.txt
</presyntaxhighlight
ユーザ(所有者)、グループ、その他ユーザの読み取り許可・不許可、書き込み許可・不許可、実行の許可・不許可は3ビットで表すので、この部分を8進数で表現することもできます。
<pre classsyntaxhighlight lang="bash">
$ chmod 600 memo.txt
$ ls -l memo.txt
-rw------- 1 hironobu hironobu 44 Sep 20 19:17 memo.txt
</presyntaxhighlight>
== グループID利用の方法 ==
<pre classsyntaxhighlight lang="bash">
$ ls -l
合計 56
-rw-r--r-- 1 taro taro 51200 2005-11-23 18:33 group_share.dat
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ chmod o-wr group_share.dat
$ chmod g+wr group_share.dat
</presyntaxhighlight>
あるいは
<pre classsyntaxhighlight lang="bash">
$ chmod 660 group_share.dat
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ ls -l
合計 56
-rw-rw---- 1 taro taro 51200 2005-11-23 18:33 group_share.dat
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
# groupadd taro-hanako
# gpasswd -a taro taro-hanako
# gpasswd -a hanako taro-hanako
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ chgrp taro-hanako group_share.dat
...
-rw-rw---- 1 taro taro-hanako 51200 2005-11-23 18:33 group_share.dat
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
hironobu 2796 0.0 1.0 8752 6716 ? R 12:14 0:05 emacs20 -geometry
...
</presyntaxhighlight>
== 現在の権限管理 ==
<pre classsyntaxhighlight lang="bash">
$ find /bin -perm +a+s -exec ls -l {} \;
-rwsr-xr-x 1 root root 26252 Mar 3 2012 /bin/fusermount
-rwsr-xr-x 1 root root 31116 Sep 13 2012 /bin/su
-rwsr-xr-x 1 root root 67720 Mar 30 2012 /bin/umount
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ find /bin -perm +g+s -exec ls -l {} \;
</presyntaxhighlight>
システムの書き換えなど重大なセキュリティ侵害からシステムを守り被害を最小限にできるようなシステムの設計にするのが現在の一般的な考え方です。
<pre classsyntaxhighlight lang="bash">
% ps -eo user,group,args | grep httpd
root root /usr/sbin/httpd
apache apache /usr/sbin/httpd
apache apache /usr/sbin/httpd
</presyntaxhighlight>
== ACL ==
<pre classsyntaxhighlight lang="bash">
$touch foo.txt
$ ls -l foo.txt
-rw-rw-r-- 1 hironobu hironobu 0 Aug 31 08:15 foo.txt
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ getfacl foo.txt
# file: foo.txt
group::rw-
other::r--
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ chmod go-rw foo.txt
$ ls -l foo.txt
-rw------- 1 hironobu hironobu 0 Aug 31 08:15 foo.txt
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ setfacl -m user:www-data:r foo.txt
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
$ getfacl foo.txt
# file: foo.txt
mask::r--
other::---
</presyntaxhighlight>
<pre classsyntaxhighlight lang="bash">
% ls -l foo.txt
-rw-r-----+ 1 hironobu hironobu 0 Aug 31 08:15 foo.txt
</presyntaxhighlight>