To log in as a different account in a Linux environment, you can use the su (substitute user) command. Here’s how to do it:
-
Open your terminal.
-
Type the following command, replacing
usernamewith the account you want to switch to:su - username -
You will be prompted to enter the password for the specified user account. Enter the password and press Enter.
If you want to switch to the root user, you can simply use:
su -
Alternatively, if you are using a system with sudo privileges, you can also switch users with:
sudo -i -u username
This will log you in as the specified user without needing to know their password, provided you have the necessary permissions.
To return to your original user account, you can type:
exit
This will log you out of the current user session and return you to the previous user.
