Advanced Commands: su - Switch 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)

Lessons in this unit:

0: Introduction
1: ▶︎ su - Switch User
2: sudo - Superuser Do
3: passwd - Change Password
4: ping - Test Network
5: traceroute - Trace Network Path
6: history - Command History
7: export - Set Environment Variables
8: crontab - Schedule Tasks
9: alias - Create Shortcuts
10: man - Manual Pages
11: tar - Archive Files
12: gzip - Compress Files
13: gunzip - Decompress Files
14: basename - Strip Directory
15: dirname - Extract Directory
16: nano - Text Editor
17: vim - Vi Improved Editor
18: emacs - Text Editor
19: ed - Line Editor

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026