How to Switch to the Specific User by Using su Command

To switch to a different user, specify the username as an argument:

su username

Replace ‘username’ with the actual username you want to switch to. You’ll be prompted to enter the password for that user.

For example: If we want to switch to a user name “shivansh260” we will use the following command

su shivansh260

Switch Users on Linux with the su Command

Switching users on a Linux system is a fundamental aspect of system administration, allowing users to perform tasks with different privileges. The ‘su’ command, short for “switch user” or “substitute user,” is a powerful tool that facilitates this transition. This article will delve into the intricacies of the ‘su’ command, exploring its various options and providing practical examples to demonstrate its usage.

Table of Content

  • Understanding the su Command
  • Basic Syntax of su Command
  • Options Available in su Command
  • How to Switch to the Root User by Using su Command
  • How to Switch to the Specific User by Using su Command
  • How to Execute a Command as Another User by Using su Command
  • How to Preserve Environment Variables while Switching User
  • How to Simulate a Login Shell

Similar Reads

Understanding the su Command

In Unix-like operating systems, the ‘su’ command, short for “substitute user,” offers a way to temporarily switch to a different user account within your current login session. This means you can adopt the privileges and permissions of the target user to perform specific tasks or access restricted files....

Basic Syntax of su Command

The basic syntax of the ‘su’ command is as follows:...

Options Available in su Command

Options Description – or –login Simulate a full login shell for the target user. -c, –command Specify a command to be executed with the new user. -s, –shell Define the shell to be used for the command. -m, -p Preserve the environment when switching users. –session-command= Run a command in a new session. –preserve-environment Preserve user environment variables. -l Synonym for –login. –help Display help information about the command. –version Display version information....

How to Switch to the Root User by Using su Command

To switch to the root user, simply type:...

How to Switch to the Specific User by Using su Command

To switch to a different user, specify the username as an argument:...

How to Execute a Command as Another User by Using su Command

You can use ‘su’ to execute a single command as another user without switching to their environment:...

How to Preserve Environment Variables while Switching User

When switching users, you might want to preserve the environment variables from the original user. Use the ‘-‘ option to achieve this:...

How to Simulate a Login Shell

To simulate a full login shell for another user, use the ‘-l’ or ‘–login’ option:...

Switch Users with su Command – FAQs

How do I switch to the root user using the su command in Linux?...

Conclusion

In this article we discussed the ‘su’ command in Linux which is essential for effective system administration, enabling users to seamlessly switch between accounts with varying privileges. This article has provided a comprehensive guide to the ‘su’ command, exploring its intricacies, syntax, and a range of options. From switching to the root user for system-wide tasks to executing specific commands as different users, the versatility of ‘su’ has been demonstrated through practical examples. Users have also been introduced to preserving environments, simulating login shells, and frequently asked questions to enhance their understanding. By following the outlined techniques and leveraging the various options available, Linux users can confidently navigate user switching scenarios for efficient system management....