Rakesh Jain
Rakesh Jain

@devops_tech

23 Tweets 36 reads Jun 30, 2023
Understanding sudo, su, su - and sudo su !
A Thread with examples ๐Ÿ‘‡
1/8 ๐Ÿฆ Welcome to today's thread! Let's dive into the world of user privileges on Linux systems.
We'll explore the differences between sudo, su, and sudo su. ๐Ÿ’ป #Linux #UserPrivileges
2/8 ๐Ÿฆ First up, sudo!
๐ŸŒŸ sudo stands for "Superuser Do." It allows regular users to perform administrative tasks by temporarily gaining root (superuser) privileges. Just add "sudo" before a cmd to execute it with elevated privileges.
eg: sudo apt-get update updates packages.
3/8 ๐Ÿฆ Next, su!
๐ŸŒŸ su stands for "Substitute User" or "Switch User." It allows you to switch to another user account, including the root account, by entering their password. It grants you access to the other user's environment.
Example: su john switches to the user "john."
4/8 ๐Ÿฆ Now, let's combine sudo and su!
๐ŸŒŸ sudo su is often used to switch directly to the root user's environment. It lets you become the root user without needing to know the root password.
Example: sudo su or sudo su - opens a new shell as the root user.
5/8 ๐Ÿฆ When to use sudo?
๐ŸŒŸ sudo is ideal when you want to execute specific commands as an administrator without switching to the root user permanently. It offers a way to delegate privileges to regular users while maintaining accountability.
6/8 ๐Ÿฆ When to use su?
๐ŸŒŸ su is useful when you need to switch to another user account entirely. For instance, if you want to access files owned by another user or work in their environment. Remember, you'll need to know the other user's password.
7/8 ๐Ÿฆ When to use sudo su?
๐ŸŒŸ sudo su is typically used when you need an extended administrative session as the root user. It eliminates the need to enter the root password repeatedly, granting you access to all files and commands.
8/8 ๐Ÿฆ That concludes our thread on sudo, su, and sudo su! Remember, with great power comes great responsibility. Always exercise caution when using root privileges and limit their usage to necessary tasks. Stay secure and keep exploring the wonderful world of Linux! ๐Ÿงโœจ #Linux
Examples of sudo, su, and sudo su ๐Ÿงต
1/6 ๐Ÿฆ Let's explore some examples to better understand sudo, su, and sudo su in action! ๐Ÿ’ป #Linux #UserPrivileges
2/6 ๐Ÿฆ Example of sudo: To update software packages, use the following command: sudo apt-get update.
By adding "sudo" before the command, you gain temporary root privileges to perform the update task. It allows regular users to execute administrative tasks securely.
3/6 ๐Ÿฆ Example of su: If you want to switch to the user "john" to access his files, enter: su john.
You'll be prompted to enter John's password. Once authenticated, you'll be in John's environment, allowing you to work with his files and execute commands as John.
4/6 ๐Ÿฆ Example of sudo su: To have an extended administrative session as the root user, simply enter sudo su.
You'll transition to the root user's environment without needing to know the root password. Now you have access to all files and commands as the root user.
5/6 ๐Ÿฆ Remember, sudo is for specific commands as an administrator, su is for switching to another user account, and sudo su is for an extended root session. Each has its use case depending on the task at hand and the level of privileges required.
6/6 ๐Ÿฆ And that wraps up our examples of sudo, su, and sudo su! Understanding their differences helps u navigate user privileges on Linux systems. Remember to use these commands responsibly, ensuring u execute administrative tasks only when necessary. Happy Linux-ing! ๐Ÿงโœจ #Linux
What is "su -" ?
1/5๐Ÿฆ The "su -" command is an extension of the "su" command, with the hyphen ("-") serving a special purpose. When you enter "su -" in the terminal, you're not only switching to another user's account but also adopting their environment.
2/5๐Ÿฆ Adopting the environment of the target user with "su -" means that you inherit their shell environment variables, home directory, working directory, and other settings. It's as if you had logged in directly as that user, providing a seamless experience.
3/5๐Ÿฆ Why use "su -" instead of just "su"?
The hyphen ensures a complete environment transition, which can be crucial for certain tasks.
For example, if you switch to the root user using "su -," you'll have access to the root user's env variables and custom configurations.
4/5๐Ÿฆ Additionally, "su -" is useful for executing scripts or commands that rely on specific environment settings. By adopting the target user's environment with the hyphen, you can ensure the necessary variables and configurations are in place.
5/5๐Ÿฆ To summarize, "su -" is an extension of the "su" command that provides a complete environment transition when switching to another user. It ensures you inherit their shell environment, making it valuable for tasks dependent on specific configurations. #Linux #CommandLine
Retweet the thread if you find it useful. Thanks!

Loading suggestions...