how to swtich user in linux terminal

How to Log in as Another User in Linux Terminal (3 Ways)

Linux can handle many users on the same system but when you only have a black screen to do everything, it’s not necessarily clear how you can switch from one user to another. In this article, I will mention 3 ways to do this.

The traditional way to log in as another user on Linux is to quit the current session with “exit” and log in again as the other user. But commands like “su” or “sudo” can also be used to switch or run a command as another system user.

Don’t worry, I’ll explain everything in detail in this article. I’ll start with the traditional method (sign off and log in as another user), but then introduce the two commands so you’ll have the answer to whatever your situation is.

Linux doesn’t have to be intimidating. With my e-book, Master Linux Commands, you’ll uncover the secrets of the terminal in a fun, step-by-step journey. From basics to scripts, get ready to level up your Linux skills. Oh, and did I mention the handy cheat sheet you get as a bonus?

1. Switch to another tab in your Linux terminal

If you know the user and password of the other account and need to use it for a while, the best option is simply to log in with the other user’s credentials.

You can either exit your current session and open a new one as the other user or, less often known, open another session without closing the current one (in a new tab).

Exit the current session and log in with another account

I guess if you’re reading this you don’t have a desktop environment and just have access to a server with one black screen where you’re logged in.

To close the current session, you can use this command:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

A new prompt will appear, asking you for a login and password. You can then type the username and password of the other user and access their files.

Note: If you have a desktop environment it won’t work in the terminal app. You need to log out via the graphic interface (generally there is a shortcut in the top-right corner or in the main menu).

Keep the current session open and switch to another user

The thing that is less known on Linux is that it’s possible to have several sessions opened at the same time. And it works on all distributions and versions (desktop environment or not).

Join Our Community!

Connect, learn, and grow with other Raspberry Pi enthusiasts. Support RaspberryTips and enjoy an ad-free reading experience. Get exclusive monthly video tutorials and many other benefits.

Learn more

By default, the system will start one main display with a login prompt when you start the computer. I guess you are now logged in on this display.

But you can then switch to another display by using this shortcut:
Where Fx is one function key, generally between F1 and F6.

If a graphic interface is installed, the GUI is generally started on F7, and F1 to F6 are simple consoles (black screens). So, for example:

  • CTRL + ALT + F2: Open a console terminal with a login prompt, where you can log in as another user.
  • CTRL + ALT + F1: Get back to your previous session (if no GUI).
  • CTRL + ALT + F7: Get back to the GUI (if you have one).

It might be slightly different depending on distributions, so check the documentation for more details, but it works like that for the most common ones.

Also, you can generally quickly switch from one console to another with “ALT+Right Arrow” or “ALT+Left Arrow”.

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

2. Use the “su” command to switch to another user

When you’re logged in via SSH, or want to stay in the same terminal in your graphic interface, the previous solution doesn’t work. Fortunately, there are commands for everything on Linux and I have two that are really useful for you.

The first command you can use to switch to another user on Linux is “su”.

The “su” command stands for “substitute user” (or “switch user”, which might be easier to remember). It’s used to change the current user in your terminal session. It’s typically used to switch to the administrator account (“root”), but you can also use it to switch to any other user.

Here is the main syntax:
su <USER>
You’ll then be prompted to type the USER password (not yours).

So, you need to know the user password to use this command. If you don’t, check the next option, which works even if you don’t know the other user’s password (but have administrator privileges).

Note: If no user is passed in the parameter, the default behavior is to switch to the “root” user.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

3. Use the “sudo” command to switch to another user

When your current user has administrator privileges, another option is to use “sudo”. Sudo stands for “superuser do” and will run the command in the parameter as root.

You probably already know that you can run a command as root, for example:
sudo apt upgrade
will install system updates using administrator privileges without really switching to the administrator’s session.

But you can also use sudo to either switch to another user, or run only one command as if it was run by this user.

To switch to another user, the syntax is:
sudo -i -u <USER>

You can also run a command as another user without switching, like this:
sudo -i -u <USER> <CMD>

The “whoami” command shows the current user. As you can see, it returns “raspberry” even if the command is run by the user “pat”.

Also, notice that no password is asked for. As I have administrator privileges (permission to use “sudo”), the system considers I don’t need the password.

Overall, “sudo” is the easiest method to switch to another user or run a command as another user when you have the right privileges. You can read this article to know how to get access to sudo with your current user (if it’s not already the case).

That’s it, you should now have at least one method that works to switch to another user on your Linux system. And if you liked this tutorial, you should also check out these on the website:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

If you are looking for exclusive tutorials, I post a new course each month, available for premium members only. Join the community to get access to all of them right now!

Additional Resources

Overwhelmed with Linux commands?
My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
Grab your copy now.

VIP Community
If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Python is a great language to get started with programming on any Linux computer.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

Similar Posts