Skip to content

Linux commands: su

A quick guide to the `su` command, used to switch the shell to another user

While you’re logged in to the terminal shell with one user, you might have the need to switch to another user.

For example you’re logged in as root to perform some maintenance, but then you want to switch to a user account.

You can do so with the su command:

su <username>

For example: su flavio.

If you’re logged in as a user, running su without anything else will prompt to enter the root user password, as that’s the default behavior.

su will start a new shell as another user.

When you’re done, typing exit in the shell will close that shell, and will return back to the current user’s shell.

The su command works on Linux. On macOS it will not work unless you enable the root user (tip: you can use sudo instead)


→ Get my Linux Command Line Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list