Hey guys, thanks for joining me again, and in this video were gonna be talking
about administrator privileges in the terminal. So, I mentioned briefly in the
previous video about file permissions, we really didn't jump in, and so I've
created a file in a location that I don't have access to. The file I've created is
etc, it's in the /etc directory, and it's just called file. So, if I change
directory to /etc and then type "'l", we can scroll here its alphabetical and so
we can see file, that's the file I created. Let's say I want to edit it, and we're gonna be
going into "nano" a lot in the future, but right now I'm going to be using nano in order to edit
to edit this file, it's a terminal application for text editing. So, I'm gonna type nano
and then in the current directory open file, and this is gonna open this file which is
great, I can view it.
But, what happens when I try to write to it, I'm gonna hit CTRL + O which is the
command to save this file, and I'm going to type enter, and its gonna give me an
error warning that I don't have permission to do this. So, if I type
if I click Ctrl + X, it's gonna ask me if I want to save changes and I'm gonna say no because I
can't. Well then how do we edit that file I just created? We need to use
administrative privileges in order to be able to edit that file. Now, there's two
ways to do this, the first one is to type sudo before the command,
and what this means is superuser do, it's an abbreviation. Superuser is a
term in Linux that identifies your privilege level. So, superuser do allows you to
make changes to files and perform administrative tasks for this one command. So,
if I type sudo nano ./file
that will let me edit the file. Now I can type test343,
hit CTRL + O, and then enter and we see a success message, wrote two lines. So, I can now
exit this and it has been saved. Now, what if I don't want to retype the entire command? So, if type
nano ./file
try to write to it and it will fail, because permission is denied.
I haven't run this specific command as sudo. So, I'm going to
going to exit. What you actually need to do is type "sudo !!"
The two exclamation marks basically mean run the previous command, so by pre-pending that with
the term sudo, it will re-run the previous command as sudo. What
if you have a lot of things to do, and you don't want to write sudo before
every single command? So, now what if you have a lot of things to do and you don't want to
type sudo in front of every single command? You could actually do this
and that's the "su" command. What this means is switch user. So, generally you type switch
user "su" followed by the name of the user account that you want to switch to. What we're going
to do is type "sudo su"and this is going to change us to the root account. As you can see, the
name pre-pending computers names, this is the computer name, and this is the name
of the current user I'm acting as which is route, and the root user has a 100%
control of everything. So, now I can type "nano file" and add a new line,
CTRL + O and CTRL + X to close it. Now, when I wanna switch back over to
my user account I'll type su nick and that's going to get me back into my user account.
So, basically if you get a permission error running a command, you might need to
run that command as sudo. For instance, if you're editing files in any directory other than
your home directory, you're not gonna have permission to those files, and we'll
go over in the future how to get permission to files. But, for right now for
all intensive purposes, these instances
is when you would run your command pre-pended with sudo. If you have a lot of
these commands to run and you don't want to type sudo before every command, just type sudo
space su. Thank you guys for watching this video! We're gonna be continuing
command line in the next video, as well, and we're going to be doing it for quite a
while, so I hope you guys are enjoying this.