<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>パーミッション  &#8211;  Linux/LPICスピードマスター</title>
	<atom:link href="https://lpic-master.com/tag/permission/feed" rel="self" type="application/rss+xml" />
	<link>https://lpic-master.com</link>
	<description>Level1,Level2 Version5.0対応</description>
	<lastBuildDate>Tue, 09 Jun 2020 06:56:47 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>

<image>
	<url>https://lpic-master.com/wp-content/uploads/2020/06/cropped-L_icon-32x32.png</url>
	<title>パーミッション  &#8211;  Linux/LPICスピードマスター</title>
	<link>https://lpic-master.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href=""/><site xmlns="com-wordpress:feed-additions:1">178194229</site>	<item>
		<title>パーミッションrwsやrwtの「s」や「t」は何？</title>
		<link>https://lpic-master.com/suid-sgid-stickybit</link>
					<comments>https://lpic-master.com/suid-sgid-stickybit#respond</comments>
		
		<dc:creator><![CDATA[りなぴ]]></dc:creator>
		<pubDate>Tue, 09 Jun 2020 06:56:45 +0000</pubDate>
				<category><![CDATA[LPIC]]></category>
		<category><![CDATA[101試験]]></category>
		<category><![CDATA[GNUとUnixコマンド]]></category>
		<category><![CDATA[LPICレベル1]]></category>
		<category><![CDATA[パーミッション]]></category>
		<guid isPermaLink="false">https://lpic-master.com/?p=166</guid>

					<description><![CDATA[たまに ls -l でファイルやディレクトリを見ると、パーミッション（アクセス権）のところに見慣れた「rwx」以外に「s」や「t」が付いているものがあります。その意味について調べてみました。 目次 パーミッションrwsの [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>たまに ls -l でファイルやディレクトリを見ると、パーミッション（アクセス権）のところに見慣れた「rwx」以外に「s」や「t」が付いているものがあります。<br>その意味について調べてみました。</p>




  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2" checked><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">パーミッションrwsの「s」はSUID、SGID</a></li><li><a href="#toc2" tabindex="0">パーミッションrwtの「t」はスティッキービット</a></li></ol>
    </div>
  </div>

<h2 class="wp-block-heading"><span id="toc1">パーミッションrwsの「s」はSUID、SGID</span></h2>



<p>パーミッション「rws」はpasswdコマンド（パスワード変更コマンド）を ls で調べると見ることができます。</p>



<pre class="wp-block-code bash"><code>$ which passwd   #passwdコマンドの場所(path)を調べる
/usr/bin/passwd

$ ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root  /usr/bin/passwd</code></pre>



<p>passwdコマンドは所有者がrootで、所有者の実行権が「s」になっています。<br>これは他のユーザーが実行した場合に、ファイル所有者の権限で実行されるという意味です。</p>



<p>つまり一般ユーザーがpasswdコマンドを実行すると、root権限で実行されます。<br>だからこそ、実行時に /etc/passwd に書き込みができるという仕組みです。<br>この仕組みを SUID といいます。</p>



<p>SUIDの設定は以下のようにします。</p>



<pre class="wp-block-code bash"><code>chmod u+s file
もしくは
chmod 4755 file  # 3桁のパーミッションに 4000 を加える

ls -l file
-rwsr-xr-x.   file</code></pre>



<p>SUIDと同じように実行時にグループの権限が適用されるようにすることもできます。<br>SGIDと言います。</p>



<pre class="wp-block-code bash"><code>chmod g+s file
もしくは
chmod 2755 file  # 3桁のパーミッションに 2000 を加える

ls -l file
-rwxr-sr-x.   file</code></pre>



<p>SGIDをディレクトリに設定しておくと、その配下で作成されたファイルはディレクトリと同じグループになるので、複数ユーザーで共有するディレクトリにSGIDを設定しておくと便利に使えます。</p>



<h2 class="wp-block-heading"><span id="toc2">パーミッションrwtの「t」はスティッキービット</span></h2>



<p>パーミッション「rwt」は /tmp ディレクトリを ls で調べると見ることができます。</p>



<pre class="wp-block-code bash"><code>ls -ld /tmp
drwxrwxrwt. 16 root root /tmp</code></pre>



<p>Otherユーザーの実行権が「x」ではなく「t」になっています。<br>これはスティッキービットというもので、この設定がされているディレクトリでは、書き込み権限があっても、自分以外のファイルを削除することができません。</p>



<p>つまり /tmp ディレクトリは、ファイル作成や、自分で作ったファイルの削除はできますが、他者のファイルは削除できないディレクトリです。<br>ただしファイルに書き込み権限があれば、書き換えることはできます。</p>



<pre class="wp-block-code bash"><code>&#91;user1@localhost ~]$ cd /tmp
&#91;user1@localhost tmp]$ vi ggg.txt  #user1でファイル作成
&#91;user1@localhost tmp]$ chmod 777 ggg.txt
&#91;user1@localhost tmp]$ ls -al ggg.txt 
-rwxrwxrwx. 1 user1 user1 9  6月  9 15:42 ggg.txt

&#91;user1@localhost tmp]$ su - user2 #user2に切り替え

&#91;user2@localhost ~]$ cd /tmp
&#91;user2@localhost tmp]$ vi ggg.txt #書き換えはできるが…
&#91;user2@localhost tmp]$ rm ggg.txt
rm: 'ggg.txt' を削除できません: 許可されていない操作です</code></pre>



<p>ディレクトリにスティッキービットを設定するには以下のようにします。</p>



<pre class="wp-block-code bash"><code>chmod o+t dir
もしくは
chmod 1777 dir   # 3桁のパーミッションに 1000 を加える

ls -ld dir
drwxrwxrwt.  dir</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://lpic-master.com/suid-sgid-stickybit/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">166</post-id>	</item>
	</channel>
</rss>
