How to change user in linux easily using “su” command

On Linux, there square measure many ways to alter this user for the session.

If you’re not employing a graphical interface, you may surprise however you’ll be able to change the user simply while not having to put in an entire program.

Luckily for you, there square measure some commands that you simply will run to realize this.

Today, we tend to square measure that specializes in the su (for switch user) and sudo commands on the LINUX operating system.

We will see the command syntax and the way it may be wont to switch users.

Linux is undoubtedly a great kind of Operating system which offers the feature of changing working sessions of an existing user to a different user hassle free. 

Multiple users are able to easily operate all their work on a single Linux based computer system with every user having its unique username and password to get login access while switching a specific user session to a different one. 

The “su” command which abbreviates to “Switch User” or “Super User” will be used for accomplishing the aforesaid task of switching user sessions.

Now, before proceeding further to elaborate the execution protocol for this Linux command, let us tell our users more about Linux OS in brief. 

More about Linux:

How to change user in Linux
Source: pixabay

There is no second thought that LINUX is formidably a great and probably the most secure type of operating system which users are using in their Computer systems for accomplishing complex tasks and operations in a convenient manner.  

Several predefined commands to perform different operations and functionality in Linux are available for the users.  

Linux commands are pretty hard to learn which doesn’t make it a user-friendly choice and that’s why it went out of fashion when Windows OS was launched.

But that doesn’t mean that Linux is not used by the users on their system nowadays.

Instead it is still one of the most preferable choices among the users who are somehow related to the hacking field. 

Learning or using Linux commands on a regular basis will help you to understand them in an appropriate manner.

There is no single way to hack a Linux based Computer system and that is definitely one of its strongest holding points over other user-friendly OS. 

Change user to root account on LINUX operating system

In some cases, you’ll ought to change this user to log because of the root account.

To change user to root account, merely run “su” or “su –” with no arguments.

$ su –


[[email protected] ~]#

$ su


[[email protected] user]#

So as we already said, we will elaborate the working protocol that will help our users to know about the guide for how to change user in Linux using the specific predefined command in our today’s blog.

By changing a user we simply mean to change a user for a current session with a new user as multiple users cannot access all the privileges of the root account user.

A root user is actually a user who can alter, create, delete or modify any file/directory from the system. 

All the privileges to perform unrestricted operations are available to the root user. Only the trusted users can enjoy all these privileges and authorities of the root user in Linux. 

In Fact to login as a root user, there is a separate working protocol which we will further mention in this blog.

But before that, let’s have a quick look on how to change user in Linux.

How to use the “su” command?

How to change user in Linux
Source: pixabay

Su” command in Linux is used when a user wishes to change the current user account with another existing user account.

Just follow these simple instructions in order to accomplish this task in a hassle-free manner:

  1. First of all, type “su” in the command prompt window. 
  2. Enter the username to which you want to switch after pressing the spacebar  once after typing su command
  3. It will now prompt you to enter the password.
  4. Enter the required password and you will successfully get a login to that username account. 
  5. Now, in case if you again wish to switch to some other username account, then type “exit” command and press “enter” to log out from that existing account. 

So, this was the simplest protocol with which you can be able to get all your answers about how to change a user in Linux. 

Whereas, things are quite different in case you switch to a specific user account directly from the root account.

Basically, when you type “su” command and username with a space in between them, then it will not ask you the password once you click the “Enter” key.

While in the opposite case, when a user is switching to a root account from a normal user account, then type “su” command and press Enter key.

It will now ask you the password of the root account as a part of security protocol.     

Change user on LINUX operating system using su

How to change user in Linux
Source: pixabay

The first thing to change your user account in shell is to use the su command.

$ su  

For example, to log in to the account named “john”, you’d run the subsequent command.

$ su john


[[email protected] user ~]$

As you’ll be able to see, by not specifying the hyphen once running su, you inherit from the environment variables of the account you’re coming back from.

To verify it, attempt to run the subsequent command

$ echo $USERNAME


To alter user by making a brand new environment, you’ve got to run su with a hyphen.

$ su – john


[[email protected] ~]$

Now, what’s more interesting in the above part of this blog is the detailed overview of the “sudo” command which is the alternate of the “su” command.

Let’s have a quick look over the sudo command. 

The sudo utility

How to change user in Linux
Source: unsplash

It is basically a more secure and advanced version of the basic “su” command that doesn’t compromise with the security protocols.

Actually when a user exclusively uses su command for switching user accounts, then the other user might have to tell his/her password to you.

Furthermore, multiple system administrators will have to share a common root account password among themselves for logging in to the root account.

That’s why sudo command is used to overcome these problems in Linux.

This command will allow all those listed users whose names are mentioned in the sudoers file to get access over someone else’s account.

Allowed users are supposed to enter their own password for the authentication. 

There is absolutely no need of sharing a root account password with every user who is operating on that specific Computer system with sudo command..

Any user can demand for the authorization to access special privileges from the Root account user.     

The syntax used for sudo command is pretty similar to the su command.

Type “sudo” in the command prompt window followed by typing the username with space in between the both.

Just enter the password then and get the access over the account of any other user you want. 

Change user on LINUX operating system using sudo

How to change user in Linux
Source: unsplash

Another way to alter this user is to use the sudo command.

By default, you may would like privileged rights to run this command, therefore certify that you simply have sudo rights either on Debian based mostly distributions or on Red Hat-based mostly distributions.

Now that you simply have sudo, to alter user you’ve got to run this command

$ sudo -u  -s

[[email protected] antoine~]$

As you’ll be able to see, you furthermore might inherit the environment variables after you use this command.

To launch a command as another user, you’ll be able to conjointly append a command to the sudo command.

$ sudo -u  

For example, to alter a user secret, you’d run

$ sudo -u john passwd

Changing user secret for user john

Current password:

New password:

Retype new password:

passwd: all authentication tokens updated with success.

Change user account using GNOME interface

If you put in Debian or CentOS with a GNOME interface, you’ll be able to conjointly change the user account by following those steps.

To change the user using GNOME, realize the ability button at the highest right corner of your screen and click on thereon.

  • Change user on LINUX operating system using GNOME
  • Click on the username label, then click on “Switch user” to alter this user.

You will be redirected to the lock screen wherever you’re unengaged to change to the account that you simply wish.


That’s all folks, we are pretty sure that you have learned quite a good things from this informative blog.

How to change user in Linux process involves use of both the su and sudo commands which are pretty easy to execute in the command prompt window.

That’s all folks, we are pretty sure that you have learned quite a good things from this informative blog.

Just go and execute these commands in your system now and experience the desired results.              

Make sure to share all your valuable thoughts and recommendations in the comments section below. Please feel free to ask any query if left below with us.

Leave a Comment