Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why is it that when I switch user 'su username' and then execute 'who am i' is outputs the previous user which I was logged as and not the one I've switched to?

share|improve this question
up vote 8 down vote accepted

You're likely running the wrong command.

  • who is meant to show who is logged in, i.e. which user owns the terminal. It returns a line like this:

    ckhan    pts/1        2012-11-05 03:06 (c-21-13-25-10.ddw.ca.isp.net)
  • whoami is mean to show you what the effective user id is of the person running it. It returns just a single name, like this (and is equivalent to running id -un):


I think you may have literally typed who am i at the terminal, which ran who with two ignored arguments (am, i).

See man who and man whoami for more details.

share|improve this answer
+1 for Nice Answer. – Md. Mahbubur R. Aaman Nov 16 '12 at 10:23

Per my Ubuntu 12.04.2 man page for the 'who' command, 'who am i' (or who with any two arguments) is the same as 'who -m' and should give you the hostname and user associated with STDIN. However I get no output with 'who am i'. Either the man page is wrong or the command has a bug. Regardless, as previously answered by ckhan, the 'whoami' command will give you the username for your effective user ID. At least in Ubuntu 12.04.2, none of id, 'who am i', or 'whoami' will give you just the username of the person logged in on the current terminal. As a workaround you could get that with:

who | sed 's/ .*//'
share|improve this answer
Note that this is Linux specific. This returns the original username in Unix / SunOS. – Underverse Nov 8 '15 at 23:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.