When you are managing a complex Ubuntu server, it is common to switch rapidly between different user accounts. You might log in as a standard user, use the su command to switch to a database administrator account to fix a table, and then switch to the root account to install new software.
After an hour of rapid context switching, running nested terminal sessions, or writing complex bash scripts that behave differently depending on who executes them, you can easily lose track of exactly which user account is currently active. If you run a destructive command while accidentally logged in as root instead of a standard user, you could completely destroy the server.
The ‘whoami’ Command
To instantly verify your current identity, Linux provides one of the simplest and most famous commands in computing history: whoami.
- Open your terminal window.
- Type the following command and press Enter:
whoami
The terminal will instantly output a single word representing your current effective username. For example:
root
If the output says root, you have absolute God-level privileges over the entire machine and should proceed with extreme caution. If it outputs john, you are operating safely as a standard user.
The ‘id’ Command (For Deeper Details)
While whoami is great for a quick check, it only tells you your name. It does not tell you what groups you belong to. For example, your username might be john, but does john have permission to use the Docker daemon or access the sudo group?
To get a complete breakdown of your permissions, use the id command.
id
This command outputs a detailed string containing your UID (User ID), your primary GID (Group ID), and a complete list of every single secondary group your account belongs to.
It will look something like this:
uid=1000(john) gid=1000(john) groups=1000(john),4(adm),27(sudo),999(docker)
This output instantly confirms that you are logged in as john, but more importantly, it confirms that john has administrative sudo privileges and is allowed to manage Docker containers.