Command Line

So, What Is ‘sudo’ Anyhow?

If you’re a new user, you’ll see commands with sudo in them and you’ve gleaned the meaning of what is sudo. The sudo command is a bit more robust than you may know and this article is going to tell you what sudo is. As I’m not actually sure how to format such an article, I’m going to try to smash it to fit my usual style article. This may make for  a fairly short article.

The sudo command stands for ‘superuser do’ and that’s probably how most folks will know it. That is, after all, correct. You use sudo when you want to execute something that requires different privileges than your account has. Most of the time, that means you want to run the command as an administrator with root privileges. 

But, that’s not all that sudo can do. You can also use it to run software as though you were another user on the same machine. Some folks (erroneously, but not without merit) have taken to referring to sudo as ‘substitute user do’. It suits, but it’s not correct.

To be fair, sudo didn’t have those extra features when it was new (~1980). When it was new, it just let you run commands as a superuser – root – and that was it. Perhaps if it had been named today, with the current feature set, those folks would be correct by calling it ‘substitute user do’. As it stands, those people are technically incorrect.

I’ve also written a couple of other sudo-related articles that may interest the reader.

Create A New User With SUDO Privileges In Ubuntu
How To: Use sudo Without A Password

What Is sudo:

The sudo command typically starts a command, such as an installation command. For example, a command like this:

sudo apt install gedit

If you try that command without a privileged account, it’ll fail and you won’t be able to install the software. For security sake, your regular user account should operate under the ‘least privilege principle’, meaning your regular account can’t be used to maliciously operate the system.

The sudo command is that safety gap. To use sudo, you must be a member of the sudoers group/have rights to the command and you must know the password. If you have sudo access, you can cause all the harm you want to a system! So, protect those passwords because they are legitimately the keys to the kingdom.

As we learn what is sudo, we might as well learn a few flags that you can use with it. The most important one, as sudo is plenty powerful by itself, is the -u flag. You use that not when you want to operate as root but when you want to use the privileges of another user on the same system. It looks like this:

sudo -u <other_username> <command>

When you’ve authenticated as sudo, you will not need to enter your password again for some period of time. The most common period of time is 5 minutes. After five minutes of non-use (idle time with no sudo commands) have passed, you will need to authenticate all over again.

If you want to exit early, you just use the -k flag. That resets everything and you’ll need to authenticate the next time you wish to use sudo. Conversely, if you use the -v flag, it will grant you another five minutes of authenticated time, allowing you to extend your sudo session.

There are a few other flags, but those aren’t really used often. Though, if you’re going to enter a lot of commands, you can use sudo -s and open a new shell where you have sudo privileges. That’s useful if you’re going to use a number of commands and don’t want them in your terminal scroll-back.

Closure:

There you have it, you can now answer the question: what is sudo? It’s a handy tool to have and there are uses most people probably never bothered learning. It’s there if you need it and you might as well be familiar with it.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Enable/Disable Your Network Interface

Today we'll cover one way to enable or disable your network interface in the Linux…

7 months ago

Check Your NIC Speed In The Terminal

Today's exercise is a nice and simple exercise where we check your NIC speed in…

7 months ago

Easily Monitor Your Wireless Connection

Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…

7 months ago

Count The Files In A Directory

I think I've covered this before with the ls command but this time we'll count…

7 months ago

Get System Information With The ‘uname’ Command In Linux

Today we'll be learning about a basic Linux command that's known as 'uname' and it…

7 months ago

hardinfo Has Been Rebooted As hardinfo2

If you've used hardinfo in the past, it may interest you to know that hardinfo…

7 months ago