A Brief look at sudo for beginners in Linux
Sudo; at some point or another while browsing the web in relation to GNU/Linux, I’m sure those of you who are new to this world would have come across this word/command.
If you’ve followed any number of tutorials scattered across the web, good chance you have used sudo before. But, what is sudo? In short, sudo is, “Super user do,†which grants the non-privileged user the ability to perform tasks that only an administrator / root, can do.
You’ve probably already encountered the use of sudo even if you haven’t popped open a terminal window, for that matter. Or even if you have NEVER USED GNU/LINUX before, I bet you’ve used sudo (or something very similar at least) even on Windows or Mac!
If you’re using Windows from Vista onward, you no doubt at least once have encountered Windows UAC (User Account Control), which albeit is NOT the sudo command and does things a little differently; for simplicity sake we could say that it’s similar enough.
GNU/Linux users who try to do something that requires administrative privileges will also encounter a pop up box asking for their password just the same, which is usually done via gksudo/kdesudo or other graphical wrappers; in simple terms they are sudo being done graphically rather than through a terminal.
Yes, gksudo/kdesudo runs a little bit deeper than that, but granted that this article is aimed at beginners, we won’t delve into the deeper aspects of gksudo/kdesudo etc VS sudo.
Mac users also experience something similar when they try to perform administrative tasks, being required to enter their password via MacOS’s own system that runs on a similar functionality to Windows UAC. Again, not quite sudo, but very similar in functionality.
How to use sudo on the command line
Using sudo is literally just as simple as prefacing nearly any command with it.
Such as typing: sudo nano /etc/nginx/nginx.conf
This command will open the specified file with the nano text editor, with raised privileges.
Editing files, pasting files, moving files, saving files, or anything short of simply viewing files as read-only, when touching files stored in root only locations, will require either the use of sudo or being superuser (su).
Why use sudo instead of su?
There are multiple reasons why it’s preferred that users use sudo, rather than logging in as root via the su command; primarily for safety and security.
When you log into your command line as su, you remain as su until you either lower your privileges, or close the command line. Sure, this enables the lazy user to have to type less by not needing to preface your commands with sudo anymore, however, this also opens the door to more potential mistakes that could become very costly; one wrong command and you could literally erase your entire hard drive.
Another reason why it’s advised not to log into your system as root, or if you want to go a step above and actually entirely disable the root account, is for security against malicious adversaries. If you have a terminal logged in as root left open on your machine, ANYONE can sit down in front of that machine and have complete administrative access.
A third reason, is because of logging differences. Typically everything you do via the sudo command is logged, on the other hand your system usually only logs the authorization of becoming su. The average user won’t really be reading a lot of these sorts of logs anyway, but for the powerusers out there this can be important.
Final words
I won’t be getting into the sudoers file, giving sudo access, limiting sudo access to specific commands etc in this article as that goes a little beyond the beginner knowledge this article was intended for. However, hopefully this gives some new GNU/Linux users a little more comprehension about exactly what sudo is, does, and its usage.
Mayor usability problem with non root account is an impossibility to connect via winSCP from Windows and have full acces for example for edit configs …
Umpal,
https://winscp.net/eng/docs/faq_su
You can use sudo with winSCP when using SCP protocol, there is just a little configuration you need to take care of first :)
Linux is so awesome, I wish it got more gaming support and I would ditch this garbage Windows is a second, I’m still sticking with Windows 7 – the last decent version they made, before they turned it into a garbage mess where milestone updates are about adding more emoji and new cat ninja wallpapers…
I first used Linux around 2008 and it was so complicated for me back then, I actually felt limited, but the more I learned how it operates, the more I like it. I hope in the future, it will get better driver support and stuff so I can use it full time.
+1
Editing files with plain sudo is a bad idea, if not even a security risk. When you edit files with sudo you should use:
sudo -e /etc/nginx/nginx.conf
or
sudoedit /etc/nginx/nginx.conf
man sudo for more info and how to change the default editor to nano.