Switching users in Linux allows you to access different accounts without logging out of your current session. This is necessary when you need to perform administrative tasks, test user permissions or access files owned by different accounts.
You will learn three methods for switching users: sudo su for administrative access, su for direct user switching and login for local systems. Each method serves different scenarios depending on your access level and requirements.
sudo methods, your account must have sudo privileges.su methods, you need the target user’s password.Before switching users, you can verify which account you are currently using. This helps confirm successful switches and prevents accidental changes to the wrong account.
whoami and press Enter. The output displays your current username.
You can now switch to a different user account using one of the methods below.
The sudo su command switches users using your own password rather than the target user’s password. This method requires sudo privileges on your account and is commonly used for administrative tasks.
sudo su username, replacing username with the target account name. Press Enter.whoami to confirm you are now operating as the target user.This method is useful when you need temporary access to another account without knowing their password. You can now perform tasks as the target user or switch to a different account.
The su command switches users by authenticating with the target user’s password. This method works without sudo privileges but requires you to know the password of the account you are switching to.
su username, replacing username with the target account name. Press Enter.
whoami to confirm you are now operating as the target user.This method is useful for testing user permissions or diagnosing access issues. You can now perform tasks as the target user or return to your original account by typing exit.
The login command provides a full login session for the target user. This method is typically used on local systems or multi-user environments rather than remote servers.
login username, replacing username with the target account name. Press Enter.This method is not supported on our VPS platform but may be available on local systems or other server environments. You can now work within a full login session as the target user.
You can now switch between Linux user accounts using sudo su, su or login commands. Each method serves different scenarios: sudo su for administrative access without the target password, su for direct switching with password authentication and login for full login sessions on local systems.
After switching users, you may need to check file ownership to verify access permissions or change file ownership with chown if adjustments are required. Our VPS management guide covers additional server administration tasks.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting