Linux How To Become Another User
If you want to become another user on Linux there is an easy and convenient command to help you do this.
If you are a regular, unprivileged user you can use the following command. This will switch to the user “user2”. It will prompt you for that user’s password before logging you in.
su - user2
If you are already logged in as root you can just run the above command without having to input a password to become the user.
If you have sudo access you can use the command with sudo. This will only require you to enter your own password.
sudo su - user2
If you want to become root there are a couple of different ways to do this. They are similar to what we covered above except that you don’t need to specify the username.
If you know the root password and direct root logins are allowed you can use the following command to become root. You will be prompted for the root password.
If you don’t know the root password but you have sudo access you can use that to login almost the same way. This will only require your own password.