2

When using a terminal session via ssh to a FreeBSD 12 server, how can I verify the name of the user in that session?

4

id

If you just need to identify your username from within the terminal session, use id(1)

For example:

id -p

uid freebsd

groups freebsd wheel

This command complies with POSIX, and supplants the whoami utility.

3

Two easy ways are with the w or who command. They will tell you who is logged in and what terminal device they are using.

$ w
11:46PM  up  3:23, 2 users, load averages: 1.45, 0.94, 0.71
USER    TTY FROM              LOGIN@  IDLE WHAT
user1      p0 :0.0              9:01PM     0 -ksh 
user2      p1 :0.0             11:42PM     0 w

$ who
user1      ttyp0    Jul 11 21:01   (:0.0)
user2      ttyp1    Jul 11 23:42   (:0.0)

To see who you logged in as, use logname.

To see what user you currently are, you can use echo $USER or whoami.

  • How do I know which user listed is the user of my session? – Basil Bourque Jul 12 at 6:54
  • Does using who presume I am a superuser? Can regular users see a list of who is logged in? – Basil Bourque Jul 12 at 6:54
  • Any user can see who is logged in with who. I'm confused why you need the user of your session. The target user you specified with ssh and the time your ssh'd in should be enough evidence to know which user you are. Another way to know what user you currently are is a simple echo $USER or logname. – Peschke Jul 12 at 6:57
  • As for why, I might have multiple terminal sessions open and lose track of which is which. Or I might open a “Console” VNC session as a backdoor access to a cloud VM such as DigitalOcean and not be fully aware of what user automatically established the session. – Basil Bourque Jul 12 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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