<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alex</title>
    <description>The latest articles on DEV Community by Alex (@loadfix).</description>
    <link>https://dev.to/loadfix</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1431419%2F0ebfd7cd-bd85-4adb-b959-7153ebb91efe.jpg</url>
      <title>DEV Community: Alex</title>
      <link>https://dev.to/loadfix</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/loadfix"/>
    <language>en</language>
    <item>
      <title>Difference between the whoami and who am i commands</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Wed, 17 Apr 2024 13:06:45 +0000</pubDate>
      <link>https://dev.to/loadfix/difference-between-the-whoami-and-who-am-i-commands-2f6k</link>
      <guid>https://dev.to/loadfix/difference-between-the-whoami-and-who-am-i-commands-2f6k</guid>
      <description>&lt;p&gt;In the world of Linux, where command-line proficiency is a valuable skill, understanding the nuances of various commands can significantly enhance user experience and system administration. Two such commands that often cause confusion due to their similar syntax and functionality are &lt;code&gt;whoami&lt;/code&gt; and &lt;code&gt;who am i&lt;/code&gt;. Despite their apparent similarities, these commands serve different purposes and provide distinct outputs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The &lt;code&gt;whoami&lt;/code&gt; Command:&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;whoami&lt;/code&gt; command is straightforward; it displays the username of the current user—the effective user ID (EUID) running the shell or script. It's a simple command without options, and its output is the username that you're operating under after any initial logins or user switches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;whoami
&lt;/span&gt;john_doe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The &lt;code&gt;who am i&lt;/code&gt; Command:&lt;/strong&gt;&lt;br&gt;
On the other hand, &lt;code&gt;who am i&lt;/code&gt; is a usage of the &lt;code&gt;who&lt;/code&gt; command with the &lt;code&gt;am i&lt;/code&gt; option. This command provides information about the original user who logged into the system, even if you've switched users using the &lt;code&gt;su&lt;/code&gt; command. It's particularly useful for checking the real user ID (RUID) when you're operating under a different user's environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;su - jane_doe
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;who &lt;/span&gt;am i
john_doe   pts/0        2024-04-08 23:20 &lt;span class="o"&gt;(&lt;/span&gt;:0&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, even though the current effective user is &lt;code&gt;jane_doe&lt;/code&gt;, &lt;code&gt;who am i&lt;/code&gt; returns &lt;code&gt;john_doe&lt;/code&gt;, which is the user that originally logged into the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparative Analysis:&lt;/strong&gt;&lt;br&gt;
The key difference lies in the context of the user identity they report. &lt;code&gt;whoami&lt;/code&gt; gives you the identity under which the current process is running, which could be the result of a series of user switches. In contrast, &lt;code&gt;who am i&lt;/code&gt; provides the identity of the user who initiated the session, regardless of any subsequent &lt;code&gt;su&lt;/code&gt; commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;whoami&lt;/code&gt; is commonly used in scripts to check the current user before executing commands that require specific user privileges.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;who am i&lt;/code&gt; is helpful for system administrators to track the original login, especially when multiple &lt;code&gt;su&lt;/code&gt; commands are used to switch between users.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>commands</category>
      <category>linux</category>
      <category>whoami</category>
      <category>who</category>
    </item>
  </channel>
</rss>
