<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>su &amp;mdash; alan</title>
    <link>https://www.franzoni.eu/alan/tag:su</link>
    <description>Alan&#39;s musings</description>
    <language>en</language>
    <pubDate>Tue, 17 Nov 2026 00:40:55 +0000</pubDate>
    <item>
      <title>Don&#39;t give a shell to system users - use su</title>
      <link>https://www.franzoni.eu/alan/dont-give-a-shell-to-system-users-use-su</link>
      <description>&lt;![CDATA[I seem very ancientwisdom-oriented these days.&#xA;&#xA;Sometimes you&#39;ve got a system user on your linux server that&#39;s used to run a specific service; it&#39;s a good practice to employ those users to achieve privilege separation, since it limits the impact of many security breaches. It&#39;s security 101, really.&#xA;&#xA;If you&#39;ve got a system user, most probably its shell would be /bin/false or /bin/nologin. Again, this is a good practice, since it would be harder for an attacker to gain shell access to your machine through that user.&#xA;&#xA;But I find that many people just change such shell, because sometimes they need to customize the environment for a user, and if you try doing something like&#xA;&#xA;su - systemuser&#xA;&#xA;you&#39;ll find yourself just back to your original shell, because su tries to invoke the shell which is set for the target user, and sudo doesn&#39;t generally help here, because its --shell option doesn&#39;t start a proper login shell for that user (most of the environment is that of the calling user).&#xA;&#xA;Very well, gentlemen: this is a wrongdoing and a potential security hole. You should never enable a shell for your system users. Instead, you should leverage an option of su:&#xA;&#xA;su - systemuser --shell /bin/bash&#xA;&#xA;That lets you choose your favourite shell on a per-launch basis.&#xA;&#xA;#MostlyUnixish #linux #ancientwisdom #su #security&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>I seem very ancientwisdom-oriented these days.</p>

<p>Sometimes you&#39;ve got a system user on your linux server that&#39;s used to run a specific service; it&#39;s a good practice to employ those users to achieve <a href="http://en.wikipedia.org/wiki/Privilege_separation" rel="nofollow">privilege separation</a>, since it limits the impact of many security breaches. It&#39;s security 101, really.</p>

<p>If you&#39;ve got a system user, most probably its shell would be <code>/bin/false</code> or <code>/bin/nologin</code>. Again, this is a good practice, since it would be harder for an attacker to gain shell access to your machine through that user.</p>

<p>But I find that many people just <strong>change</strong> such shell, because sometimes they need to customize the environment for a user, and if you try doing something like</p>

<pre><code>su - systemuser
</code></pre>

<p>you&#39;ll find yourself just back to your original shell, because <strong>su</strong> tries to invoke the shell which is set for the target user, and <code>sudo</code> doesn&#39;t generally help here, because its <code>--shell</code> option doesn&#39;t start a proper login shell for that user (most of the environment is that of the calling user).</p>

<p>Very well, gentlemen: <strong>this is a wrongdoing and a potential security hole</strong>. You should <strong>never</strong> enable a shell for your system users. Instead, you should leverage an option of <strong>su</strong>:</p>

<pre><code>su - systemuser --shell /bin/bash
</code></pre>

<p>That lets you choose your favourite shell on a per-launch basis.</p>

<p><a href="/alan/tag:MostlyUnixish" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">MostlyUnixish</span></a> <a href="/alan/tag:linux" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">linux</span></a> <a href="/alan/tag:ancientwisdom" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ancientwisdom</span></a> <a href="/alan/tag:su" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">su</span></a> <a href="/alan/tag:security" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">security</span></a></p>
]]></content:encoded>
      <guid>https://www.franzoni.eu/alan/dont-give-a-shell-to-system-users-use-su</guid>
      <pubDate>Thu, 11 Dec 2014 22:25:00 +0000</pubDate>
    </item>
  </channel>
</rss>