Sudo

Anyone who works in a Unix or Linux environment is familiar with the sudo command. Sudo allows the user to execute a command as root. That’s sometimes necessary even for the most basic users who aren’t operating on a locked down machine controlled by a system admin. Back when I was learning Unix, everyone just used su to become root but security concerns lead to the use of sudo instead.

The problem with sudo is that it’s good for one command only. That’s great if all you want to do edit a system file or copy a file to one of the system directories but it gets to be a pain when your task involves several commands. Very often, you really do want a root shell.

It turns out that the sudo command can do that too. If you invoke it with the i or s flags, it will give you a root shell. There’s a subtle but significant difference between the two flags. Fortunately, Derrik Diener over at maketecheasier explains all this in his article The Differences between Su, Sudo Su, Sudo -s and Sudo -i. It covers everything you need to know but the TL;DR is that you usually want sudo -i although sudo -s is also useful.

Apple doesn’t reveal the root password on Macs but it’s easy to reset using sudo. When I got my first Mac, I did that but now I don’t bother; sudo does everything I need. By using the i or s flag, I can also get a root shell when I need one. If you’re a sudo user, be sure to take a look at Diener’s post.

This entry was posted in General and tagged , . Bookmark the permalink.