Executing “who am i” in tmux doesn’t show result

tmux

when I am in a tmux session and execute "who am i" I don't get anything back. It seems tmux somehow breaks "who am i". Is there a fix for that?

Edit to clarify what is happening:
I have a script that is executed as root user and I want to be able to log who executes it.

If someone

  1. Logs in with their user using ssh
  2. Does an su -
  3. Executes the script then who am i returns the login user and IP of the clent

I noticed if someone uses tmux in between then this doesn't work anymore

  1. Log in with their user using ssh
  2. tmux (in case they get disconnected)
  3. su -
  4. who am i returns nothing. whoami and $USER show root

Best Answer

  • It seems tmux has to be built with --enable-utempter to update utmp(5). Then a proper binary must be available.

    In your case who am i inside tmux finds no entry associated with stdin (which in tmux is like pts/1 or so; pseudo terminal slave). Possibilities:

    • Your tmux was built without --enable-utempter and therefore did not try to update utmp (to register the pseudo terminal slave there) when the pane was created.

    • Or there is no utempter executable tmux can use. In my Debian 9 it's

      /usr/lib/x86_64-linux-gnu/utempter/utempter
      

      (just in case: permissions rwxr-sr-x, ownership root:utmp).

    To fix, make sure you have utempter. In Debian 9 it's in the libutempter0 package. If the file is there and the problem persists then most likely you need to rebuild tmux, this time with --enable-utempter.