If you want to do a task with a particular user account that you are not currently logged in to, you usually change your user account for some time to complete that task. However, if you want to save yourself the whole process of changing users, you can also do it through the Linux terminal. In both cases, however, you’ll need to enter the login password for that user account before you can access it.
Fortunately, you can even bypass this password on Linux if you don’t know it or don’t want to enter it for some reason. You can do this by using the “su” command to switch from your current user account to your desired user account without entering its password. The whole process will become clearer to you if you go through the method of switching to another user account without specifying the password using the “su” command in Ubuntu 20.04.
Switching to another User Account without providing its Password using the “su” command in Ubuntu
For switching to another user account without providing its password using the “su” command in Ubuntu 20.04, you will have to perform the following three steps in the specified order:
Step # 1: Access the Sudoers File in Ubuntu 20.04
First, you need to access the Sudoers file in Ubuntu 20.04. This can be done by executing the command shown below in Ubuntu 20.04 terminal:
The Sudoers file of our Ubuntu 20.04 system is shown in the following image. This file contains the details of the access privileges that are granted to each user account of your Ubuntu 20.04 system.
Step # 2: Modify the Sudoers File in Ubuntu 20.04
Now, you need to modify the Sudoers file in a way that you can easily switch to the desired user account without providing its password while still being logged into your current user account in Ubuntu 20.04. You have to locate the line “%sudo ALL=(ALL:ALL) ALL” in the Sudoers file and add the line that follows below it:
kbuzdar ALL=NOPASSWD: /bin/su - ayesha
Here, you have to replace “kbuzdar” with the name of the user account to which you are currently logged in and “ayesha” with the name of the user account to which you want to switch without providing its password. After doing this, you can save and close your file to proceed further.
Step # 3: Switch to the Desired User Account without providing its Password using the “su” command
Once the modifications in the Sudoers file are done, we can attempt switching to the desired user account with our current user account in Ubuntu 20.04. For that, we have to execute the command shown below:
sudo su - ayesha
Here, you have to replace “ayesha” with the name of the user account to which you want to switch without providing its password.
Once you will execute this command, you will notice that you are not being prompted to enter the password of the desired user account. Rather you have successfully switched to your desired user account without providing its password as shown in the following image:
Now, you can execute any command of your choice with the user account that you have just switched to. However, as soon as you will close the current terminal session and reopen it, you will be switched back to your current user account.
This article presented to you the easiest way of switching to any desired user account without providing its password in Ubuntu 20.04. With this tutorial, you would have realized that a slight modification in the Sudoers file paired with the “su” command can do wonders if you use it correctly in Ubuntu 20.04.