Which Command Should You Use?

Which Command Should You Use?

Depending on your Linux setup, you may perform administrative tasks using either the su command or sudo. It's easy to confuse these two commands since both of them have similar functions.

So, which command should you use? Let's find out.

Su Gives You Full Root Access

The traditional way to access the root account to configure a Linux system, going back to the Unix days, is using the su command:

su –

The "-" means that you'll have the same environment as you would if you logged in directly as root. The system will prompt you for your password. If you're successful, the prompt will change to a "#" character. You can then run any commands you need to as root.

Type logout or hit Ctrl + D to return to the standard user privilege when you're finished.

While su is useful, the main problem is that it's an all-or-nothing option. You have full root access or ordinary privileges. If you have multiple administrators on a server, you'll have to share the same root password.

Sudo Gives You More Control

More Linux distributions like Debian and Ubuntu are installing sudo by default because it's safer than using su. It's a mature tool that's been around since 1980.

Sure, you only have to remember one password, but sudo's full power comes with managing multiple admins on multiple machines. It's so useful that sudo has been immortalized in geek culture in a famous XKCD comic. You can even configure sudo to run without a password, but this is obviously not recommended for servers where security is paramount.

In addition to full root access as with su, you can specify which users can run which commands on which systems in the /etc/sudoers file. Because of the flexibility of sudo, the /etc/sudoers syntax is complex.

Related: How to Add a User to the Sudoers List in Linux

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.