How to change current user?

QuestionsQuestions8 SkillsProYour First Linux LabAug, 26 2025
0197

To change the current user in a Linux environment, you can use the su (substitute user) command or the sudo command. Here’s how to use both:

Using su Command

  1. Switch to Another User: To switch to another user, use the following command:

    su - username

    Replace username with the actual username you want to switch to. The - option ensures that you also switch to the user's environment.

  2. Enter Password: You will be prompted to enter the password for the specified user.

Using sudo Command

  1. Run a Command as Another User: If you want to run a command as another user without switching the entire session, you can use:

    sudo -u username command

    Replace username with the target user and command with the command you want to execute.

  2. Enter Your Password: You will need to enter your own password (not the target user's password) if you have the necessary permissions.

Example

To switch to the user john, you would use:

su - john

Or to run a command as john:

sudo -u john ls /home/john

Note

  • Ensure you have the necessary permissions to switch users, especially when using su or sudo.
  • If you are using su to switch to the root user, you can simply use su without specifying a username.

0 Comments

no data
Be the first to share your comment!