Why sudo instead of su




















Sudo stands for either "substitute user do" or "super user do" and it allows you to elevate your current user account to have root privileges temporarily. Once that time expires, you have to enter your password again to regain root privilege. Having root user privileges can be dangerous, but using sudo instead of su can help you keep your system secure. If you are using Linux and you want your actions to be safe, you need to know and understand these two commands.

In Ubuntu Linux, the root account is not configured by default. Whenever a user tries to install, remove or change any piece of software, he has to have the root privileges to perform such tasks. The sudo command is used to give such permissions to any particular command that a user wants to execute once the user enters a user password to give system based permissions.

The user will be prompted for the password of the user to which he or she is switching. Here is an example:. The per can also use it to switch to the root account. If you use a traditional Linux setup, you are familiar with using the su command to gain root privileges.

You can use it to log in as the root. If you are using a type that relies on su and allows root user login, log in as your standard user and su to the root user.

In fact, using Ubuntu, the root user account is disabled, thank goodness. You also cannot use su to become the root user.

You can only issue commands using sudo to gain administrative privileges. I caution you to ensure this is appropriate for your security needs before providing a user the power of sudo. Using the basic form of sudo is pretty simple. Consider that you have to run the dpkg to install new software on your computer.

If, as a standard user, you just issue the command dpkg -i software. This is because standard users, by default, cannot install applications on a Linux machine. To install an application on a Linux machine, you must have super user privileges. But you will see an error if you are not root or in the sudo group. Instead, if you run this command:.

You will be asked to type your password, and then you can run the command if you are a part of the sudo group.

The theory behind using sudo is that the act of issuing the sudo command before any command you run makes you think more about what you're doing and hopefully make fewer mistakes with an account that possesses unlimited power. You are basically switching to a particular user and you need the password for the user you are switching to. Most often, the user account you switch to is the root account but it can be any account on the system.

In the above example, you are switching to root and you need the root password. The - switch provides you with root's environment path and shell variables rather than simply giving you root user power for a single command while keeping your own environment. For the second example, you are switching to bryant , and so you need bryant's password unless you are root. If you want to switch to the bryant user account including bryant's path and environment variables, use the - switch:.

The - switch has the same effect as logging into a system directly with that user account. In essence, you become that user. Check out the IT security and compliance checklist. But when do you use one, not another? Since sudo can pretty much do everything that su can, I would say it is best to stick with sudo unless you are working with some legacy codes that require the su command.

Bryant Jimin Son is a Consultant at Red Hat, a technology company known for its Linux server and opensource contributions.

How Does the su — [hyphen] Command Work? Introduction The sudo and su commands belong to the group of commands every Linux user comes across. Was this article helpful? Sofija Simic. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology.

She is committed to unscrambling confusing IT concepts and streamlining intricate software installations. Next you should read. SysAdmin Web Servers. Ubuntu You can upgrade to the latest release from an Linux stores visible and hidden files in its directories. You can display these hidden files using simple Since Linux introduced the apt command line tool with the Ubuntu The shutdown command is used to shut down the system immediately, schedule a shutdown, inform users of such The best answers are voted up and rise to the top.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. What are the benefits of sudo over su? Ask Question. Asked 9 years, 6 months ago.

Active 1 year, 2 months ago. Viewed 27k times. What is the actual benefit that Ubuntu or Debian derivatives achieve by disabling root user? So in what case root can cause damage whereas sudo can't?

PS: I know how sudo works. Improve this question. Cristiana Nicolae 4, 9 9 gold badges 27 27 silver badges 46 46 bronze badges. Web-E Web-E Add a comment. Active Oldest Votes. Improve this answer.

The "think before you leap" logic is as naive as thinking users will stop to think when shown a dialog box that says "Do you really want to install TrashTheComputer. DanNeely - I don't think so. I type a lot of commands, and most of them don't require sudo , so I don't use it.

When I do use it, it gives me a moment of pause. Yes, I'm speaking as a programmer, not an average user, but then again, average users don't use the command line. NathanLong not quite true with Linux, the reason this question exists shows an "average user" not understanding why to use sudo over su. Too often, people say "use sudo because it's safer than su" - which is naive to think as it isn't any safer at all.

To forget you used su is no excuse, that's just down-right incompetence if you run a command as root accidentally. In point of fact, OP has questions on StackOverflow.



0コメント

  • 1000 / 1000