Start a Shell as Another User

Start a Shell as Another User

You are administering the practice VM and want to see what working as the school assistant feels like. su starts a shell as another user under the system's authentication rules. This changes the identity of a new session; it does not edit your original shell into a different person.

The environment choice matters too. A login-style switch aims to set up a session like that user's login, while a plain switch can retain more of the invoking environment. Let's make the login-style intent explicit and learn how to return.

What you’ll learn

  • Start a shell as a different user with su.
  • Distinguish an ordinary switch from a login-style environment.

Switching identity also raises an environment choice

  1. Current session

    Your existing shell has its own identity and environment.

    current user
  2. Login-style switch

    su - starts the target user’s login-style shell under local rules.

    school-assistant
  3. Return

    exit leaves that shell and returns to the original session.

    original user
When switching users, ask both whose identity you need and what environment you intend.

Enter and leave a login-style assistant shell

Prepare the example

Use an existing practice account with an appropriate usable shell and follow the VM's authentication policy. Run this interactively, because authentication may prompt and a new shell will begin. Do not assume the password or authorization rules are identical across Linux distributions.

Bash · Linux terminal

su - school-assistant
id
exit

Expected behavior; machine-dependent details

Identity output depends on the target account; exit returns to the original shell.

su - school-assistant requests a login-style shell for the target user. After it succeeds, run id inside that shell to inspect its identity and groups. The hyphen is a meaningful option here; it affects environment and startup behavior rather than naming a file.

exit ends the target shell and returns you to the original session. This boundary is helpful: you can test an assistant's access without forgetting which identity owns the current prompt. Local settings and startup files still influence the environment, so inspect it instead of assuming a switch reproduces every aspect of a graphical or remote login.

Identity, environment and leaving the target shell

The su command starts a shell as another user. It is useful when you need to test permissions or work inside another account's session context.

What is the su Command?

su stands for “substitute user” or “switch user.” It allows you to temporarily log in as another user without fully logging out or switching terminals.

By default, running su without a username will attempt to switch to the root user.

Syntax

su [options] [username]

Example 1: Switch to the root user

su

You’ll be prompted to enter the root password.

Password: 
# (Now you’re operating as root!)

Example 2: Switch to another user

su john
Password: 
$ (Now you're logged in as user 'john')

Tip: Confirm the Current User

whoami
john

What if you get an authentication error?

Make sure the target user has a password set and that you typed it correctly. The root user must also have permission to switch to that account.

Important Security Note

  • Using su gives you full control of the target user’s environment.
  • Be very cautious when switching to root, as this gives you access to modify or delete critical system files.
  • Always log out of the root session when done. Just type exit.

Exiting the su session

exit
$ (Back to your original user)

Switch user sessions with su

Let’s quickly review what we’ve learned:

  • Use su to switch to another user.
  • Use su username to switch to a specific user.
  • Type exit to return to your original session.

And that’s it! You now know how to use the su command confidently.

Happy terminal-ing!

Try it, then check the worked answer

Your task: Which form requests a login-style environment?

Use an existing practice account with an appropriate usable shell and follow the VM's authentication policy. Run this interactively, because authentication may prompt and a new shell will begin. Do not assume the password or authorization rules are identical across Linux distributions.

Bash · complete example for this question

su - school-assistant
id
exit

Expected behavior; machine-dependent details

Identity output depends on the target account; exit returns to the original shell.

Worked answer

su - school-assistant

Choose su - school-assistant for login-style behavior. A plain su is not guaranteed to reset everything identically. The -c option asks to execute a command, which is another mode rather than a substitute for the requested session style.

Check your decision

Which form requests a login-style environment?
Choose one answer. You can try again.

Answer and explanation

su - school-assistant

Choose su - school-assistant for login-style behavior. A plain su is not guaranteed to reset everything identically. The -c option asks to execute a command, which is another mode rather than a substitute for the requested session style.

Choose the session environment deliberately

When switching users, ask both whose identity you need and what environment you intend. Check id inside the new shell, then leave it deliberately with exit. Knowing the active identity is essential when interpreting permissions or running an administrative operation.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Run One Command with sudo →