Learn Linux on the Command Line (Full 8-Hour Hands-On Course)
Read full transcript 417 segments
-
Welcome to the complete eight-hour Linux course. Linux powers the world. Most websites and supercomputers run on it. And if you want a tech job in 2027, this is where it all begins. Software, DevOps, or AI engineers all need hands-on Linux skills on the command line. But there are two types of people learning Linux. Those who memorize a few commands, follow tutorials, and then get stuck the moment something goes wrong. And there are those who actually know how to work with Linux. They connect to servers, they manage systems, troubleshoot problems, and figure things out on their own. This course makes you the second type. I've taught Linux to well over 10,000 engineers, and I've helped over a thousand people land DevOps jobs inside KubeCraft, my DevOps career program. And today you get the exact same Linux training they follow inside of KubeCraft. We'll start by setting up your own server, and then you'll master the command line. We'll dive into the Linux file system, permissions, and essential commands. And from there, we'll go into processes, networking, SSH, tmux, and customizing your own environment. And by the end, you'll have the practical Linux foundation that you need for Docker, Kubernetes, and DevOps. [music] Now open your terminal and let's learn Linux.
-
And welcome to the course where I'm going to be teaching you Linux on the command line. So first of all, this course is very specifically designed to teach you how to work on the command line. Linux can be run in several ways. So if you see my screen here, I am actually running Linux on this computer. What you see here is Linux. So this is a graphical rendering of Linux, okay? So this is a a a desktop version of Linux where I can load programs, where I can have my command line, I can have I can work on graphical programs, but I also have the ability to run like on the terminal. But there's a difference between having this available, this environment, and running on the command line. This is what you see here. This is the command line interface, and I can issue commands here. I can edit text files, I can interact. If I do cat etc OS release, then I can see what I'm running right now. So this this is the command line, and that is what we're going to be focusing on.
-
Because this is what you should do if you want to become a professional in this space. You There are so many DevOps engineers out there who call themselves DevOps engineer, but who are unable to do this, who are unable to go on the command line and issue commands. All they can do is go to the AWS portal and click around, and they are completely helpless when they don't when they're not when they need to work on the command line. So that's what we're going to be focusing on here. Now Linux has several distributions. Linux is the operating system. It has the kernel, and we're going to be I'm going to be explaining this more in more depth in the future modules. But you Linux has the kernel, and then there's a distribution which packages a lot of things with that kernel. A distribution of Linux is basically a flavor of Linux, and there are thousands of them out there. But the one that we're going to be using here is Ubuntu Server. So if you go to the internet and you Google Ubuntu Server, then you're going to be able to download Ubuntu Server.
-
It is completely for free, and we choose Ubuntu Server because it's one of the most common operating systems that is used in production by actual companies. Ubuntu Server is powering millions and millions of web servers around the world. Google is mainly using Ubuntu Server. So it is a very safe operating system to learn which is used in many many companies. Also it is the easiest one to get started with. So, we're going to be using Ubuntu Server. And I'm going to show you how to download it, how to install it, and anything everything. One important thing that we need to address first is hardware versus virtual machines, okay? So, there are multiple ways of running a Linux distribution. So, I'm going to go to X Color Draw here. And if I just create something here.
-
So, the what you can do is let's say you have your computer here. This is my computer. And I can install Windows on here, for example. And then Windows is my operating system, okay? This is what is running my computer. In this case, what you see here, I am running Linux. Linux is my operating system. And I I think that the best way to learn Linux properly and how to work with computers properly is to install Linux directly on a machine. So, I like, for example, you take a laptop and then you install Linux on there. Or you take a Raspberry Pi and you install Linux on there. I'm going to get into why I think that that's the best. But the alternative is what many people do is they create a virtual machine. So, let's say I have a Windows computer. What I can do is there is something that's called a hypervisor.
-
There's software available that basically creates a mini computer on your computer so that you can run a Linux mini computer on your computer. And that is what is called virtualization. This is now a virtual machine. So, you can if you have a Windows machine, you can run a mini Linux machine on there. And that is called a virtual machine. Now, I do not recommend using virtual machines. And I'm going to be linking a video where I explain this in depth. If you want to know more why I think this way, but I think I've thought about this for hundreds of hours. So I I I teach people to do this for a living. So I I know what I'm talking about, but the best way to learn it all comes down to how are you going to learn the fastest and the best, okay? And um in that video I will explain it, but I think that you learn better when you have a physical device. Let's say it is a laptop or something and you actually have your USB stick and you're working on the device, it becomes very real and very tactical.
-
And just like um there are studies showing that if you if you're taking notes and if you write it by hand, you will actually remember better if you're writing by hand because your your brain is interacting physically, so you and visually. So you see what you're writing, you have the touch sense, you have the the muscle um motoring and and reaction. So there's many many more aspects of the brain involved with it. So when it becomes physical and you see it in front of you, it is I think I I claim that you learn better and faster that way. And also it is a more satisfying experience. But it does require that you need to have hardware. Well, the good news is that you can use basically anything you have lying around. If you have an old laptop, if you have an old gaming PC or an old desktop PC, the great thing about Linux is that it runs on anything.
-
Any old computer that you have lying around is going to be able to run Linux. And this is why Linux is so cool because it will be able to breathe life into old machines right? So if you like I'm 99% sure that you have an old laptop lying your closet somewhere. That is enough. If you don't have that, then if you ask your friends, your family, or anything anyone you know, do you have an old laptop that I could borrow, that I could buy for very cheap? I'm 100% sure you'll be able to get an old laptop, okay? That is all you need. You don't need more than that. So before going the virtual machine route, I strongly, strongly recommend to first see if you can get an old laptop, an old PC, or something just to have a physical device to do it. The reason I say this is because in your career, we're going to be working towards something that's called a home lab where you have your own servers running your own programs, right?
-
And this is a very satisfying hobby that is going to teach you a lot, but which is also going to aid you in landing jobs. So it's this this is on we're now in the beginning stages, but when you follow the CubeCraft way, which thousands of people have done that towards landing actual DevOps jobs in the field, you're going to be running your own home lab with infrastructure in your own home using cheap hardware. It doesn't have to cost much, but it is also an investment in your own career and it will be a good vehicle for you to learn and also to land jobs. So this is why I strongly recommend you go and do it properly right from the get-go. If you do not want to follow the advice and you still want to go for virtual machines, then that is fine. But before we do that, I just want to also highlight one more option, which is the Raspberry Pi.
-
And that is actually the the machine that I'm using in the actual course here that you will see. A Raspberry Pi is a very small and cheap device that you can buy. It's a very small computer. Like it's a very small single board computer. This is what it looks like. It's a very small little computer and it's super cute and it's really it's it's really tech, it's really nerdy, but it's a really small little computer that basically can do anything. It's a very versatile device and you can you can do so much with Raspberry Pis. Like we're using it as a server to run stuff on, but you can use it to learn electronics, you can use it to learn programming. It's very fun to use for kids projects, everything. So buying one Raspberry Pi is almost a necessity if you are going to be a serious tech worker and they're really cheap. So if you don't have a laptop or you don't want to use a laptop, then I recommend buying a Raspberry Pi. So Raspberry Pi price Amazon, let's just check what they're what they're costing now Raspberry Pi on amazon.com.
-
Currently a Rasp Raspberry Pi 5. So this is a Raspberry Pi 5 4 GB. This is now €65 currently. So that's about $70 or something like that. Or it's about $60 and this is the 4 GB one. If you're going for this, then I do recommend going straight away for the 8 GB one. So let's see. Let's visit the Raspberry Pi store. They should have it here. Well, Raspberry Pi 5 8 GB. This is the one that I recommend you get. The the 4 GB is fine to use with this course. You don't need to you don't need 8 GB, but the reason why I recommend 8 GB is because when you're already paying €65 for €30 more, you get double the memory and you can do more with it in the future, okay? So I this is a really good investment in career and you're going to absolutely love it. It's only 100 bucks and you're you can learn you can do the full cube craft curriculum on a Raspberry Pi just so you know that I in um I teach a all of the Kubernetes courses everything is done on a single Raspberry Pi and I do that just to prove a point that you don't need tons of big server racks and you have to
-
spend a lot of money. You can literally create a six-figure career on a $100 device and I I do that to prove a point in the courses. But literally one or two of these devices is all you need for your home lab and for everything. So I strongly this is actually what I'm using in the course and that's what I recommend to get a Raspberry Pi invest in yourself and um you won't regret it. You won't regret it. Uh so this is the one that I actually use. So if you do go the Raspberry Pi route there's a complete video in this course that shows you how to get started on that how to install Linux on it. If you go the old laptop route then what I recommend is um what you do is you have to go and create a USB stick and if you are running Windows right now you're going to be using a program called Rufus. So it's rufus.
-
ie you just Google and then you'll find Rufus and you you can create bootable USB drives the easy way and it's very easy if you just Google install Linux uh Ubuntu server Rufus then it it you're going to be seeing a lot of um guides here's the official Ubuntu guide actually. So what you do is you write a bootable USB device and then what you need to do is you need to enter the BIOS on your laptop. Now that is a little bit tricky sometimes but if you have a ThinkPad for example so enter what you Google is enter BIOS ThinkPad because the BIOS is uh when you start your computer, first it loads the BIOS and then it's going to load the operating system that's installed whether it be Windows or Linux or whatever. So if you need to enter your BIOS, you just Google the model of your laptop and then uh the model and then how to enter BIOS and then there are are bound to be guides for that. But it's usually pressing the F2 or the F8 button or the delete key.
-
There's something you need to do when you power on the laptop. You have to like spam the delete button or the F8 button in order to start the BIOS, but it's different for every uh every machine or every model. And when you are entering in the entered in the BIOS, what you then need to do is you have to select your USB drive and tell the computer, hey, instead of going to the hard drive, I need you to look at this one instead because I want to install something new. So it's a little bit trickier and tech more technical, but you're going to be learning a lot if you go through this um and and this is also one recommended route. The Raspberry Pi route is completely documented in this course. I will show you exactly how to do it. Using an old laptop is almost impossible to create a course for because there's so many flavors and variations out there. So you will figure it out if you just get the laptop by do the USB and and maybe do a bit of Googling, but you will figure it out.
-
But only only if you if you don't want to get a Raspberry Pi, if you don't want to do the old laptop and by the way, if you're running on macOS, then you should use Balena Etcher to create that USB stick. But only if you don't want to use the laptop, you refuse to buy a Pi, that is when you're going to be looking at a virtual machine. So to get the virtual machine on Windows, we're going to be using VMware Workstation Pro, which is a free program. And the Windows video that you that's below here is going to show you how to install it and how to set up a Linux virtual machine on there. Now you may know about WSL, Windows Subsystem for Linux, and I do not recommend that you use this at all. The reason for that is because it is a sort of an abstraction that is built into um Windows. But what we want to actually do is we want to train ourselves to be able to SSH, and you're going to learn what SSH is. But we are going to want to train ourselves to be able to connect to remote servers just like you would do at work. And at work, if you have this WSL thing, you're not going to learn the skills on how to connect to a different machine from your own machine. So do not use WSL. Just follow the guide here.
-
If you're running on macOS, then you're going to be using UTM. It's a program to create virtual machines on UT on macOS. And that is the one uh that which also documented here. So that is the introduction. Make your choice. I strongly recommend you go for the Raspberry Pi route. And if you want to do the virtual machine route, that's fine too. And then you could just pick the video that you the route that you're going to go, install Linux, and then we can continue with the course. Hello. In this module, we're going to be setting up a virtual machine on Windows, Windows 11. Uh to be honest, I have not used Windows in 4 years now, so this is all a little bit unfamiliar and uneasy for me, but I did manage to figure it out. So what we're going to do is uh you're going to go to follow the link that I just that that will be included with this module.
-
And there's a Reddit thread here where it says, how can I download VMware Player? Okay? VMware is a company that creates enterprise-grade virtual virtualization software. And they have a product called VMware Workstation. And they recently, well, recently, I think it's it's all almost two years ago now, but they made that free for for everyone. The only thing is that you have to make an account etc. Uh I just lost two days of my life trying to get this to work on Windows with VirtualBox and other VM solutions. VMware Workstation is the one to use, the one that you're that you should be using. Um so it is worth creating the account. Here there are links. I'm going to this is the correct link, support.broadcom.com etc. The link will be included in this module. You click that link and then you create an account. And it's a little bit of a annoying process. It's not completely um smooth, but where you want to end up at this page where it says my dashboard here.
-
That that this is what you need. So the the URL is support.broadcom.com/group/ ECX/mydashboard. Okay? This is the place where you want to end up. Then there is the my downloads section. And then here you can see this free downloads available here. You click that. And then here you're going to look for VMware Workstation Pro. So you click that. And then you can um select window VMware Workstation for Windows. And then here you click the release. And then here you click this button to download it. Now it's going to ask for your address and all those things and you have to do it in order otherwise they won't give you it. But then you click this and then you get a file which is called VMware Workstation Full .exe. You double click that and then you just follow the installer okay?
-
When you've done that, then this is what you get. This is the VMware Workstation Pro. This is the UI that you want to see okay? Next, we're going to go and Google Ubuntu server download. And Ubuntu server download, you go here and it's very important that you go here and it says get Ubuntu server. Not Ubuntu desktop, not Ubuntu core or cloud, Ubuntu server. That's the one that you want. And then you're going to get the Ubuntu 24 LTS version. Now, if your if the LTS version is 25 now, it doesn't really matter. It depends on when you're looking it. What's important here is that you pick the LTS version. LTS stands for long-term support. This is the stable version of the Ubuntu server distribution. And this is the one that we're going to be using in this course. So you click download Ubuntu LTS here. And then when you download that, again, you're going to get a file which is called an .iso file.
-
When you have that file, then you're going to go to VMware Workstation Pro and then you're going to click create a new virtual machine. Here you get a wizard. Now, you're just going to use the typical one, okay? You just go typical and then you click next. And then here you find here you have to find the installer disk. So you browse. And in my case, it is located in downloads. And then you click this Ubuntu 24 .iso file that you have just downloaded from the Ubuntu website. And again, it's important that you pick Ubuntu server. So you download this. Then you click next. Yes, you click next. And then you give it a name. So I'm just going to give this Ubuntu 64 the name. Location, just let it choose that. And then for the disk size, I'm just going to give this 200 GB. It can be 50 like 20 is probably enough, but just give it like a few hundred just so that you know that you can install whatever you want. Okay?
-
Click next. And then that's it. You don't have to change anything else. The network adapter is automatically set to NAT. That is what you want. So you just you just follow the wizard and you click next, next, next and finish. And now it's going to power on. So now we wait for this to power on. And I just click okay. And here this is now very small. So now I'm going to click view. And I'm going to say stretch guest. And I'm going to click keep aspect ratio stretch. Okay? And now I have a better readable format. I'm going to click inside here. And now if I am now I'm able to move this with my arrow keys. Okay? If I if I now move my mouse, you will see I can't move my mouse anymore.
-
To go out of here, in the bottom left of the screen, you will see an instruction that says press control alt to release. So I'm going to press control alt on my keyboard and now I can use my mouse again. Okay? So when you click inside, it gets the mouse. You can't use it. Control alt, it goes out and I can use my mouse again. So again, I'm clicking inside of this screen and going to all the way to the top, try or install Ubuntu server. That's the one that I'm going to pick and then I'm pressing enter. Now this is going to start a live environment, a live installer. And this is going to um load all of the stuff that we need in order to install Ubuntu server. So this takes a second or two. So let's just wait for As you see, it takes it takes a few minutes for it to completely start up, but that's completely fine. Okay, so now we see the installation wizard. This is where we want to start working.
-
So here I am again, I can click my arrow keys and this is how I can navigate. So I'm just going to use English and press enter. Here the keyboard layout is fine, so I'm going to press enter. And here I'm going to just press enter again because we want the normal Ubuntu server installation. And now we see that this is important that the the there there is an IP address on the top, okay? So there is an IP address where it says DHCP V4. In the middle of the screen here it says that and then it has a number. In my case, 192 168 126 129, okay? You this is you want to see this. You want to you have to wait and it might it may take a while for this to come up, but it should just work out of the box, but then I want you to write down this number.
-
But you have to if if you don't see this number, don't continue. You may have to do some debugging, but this should work out of the box where you see this IP address because this means that the machine virtual machine has a net internet connection. So it it just worked, so I'm just going to click done. Again, just click enter. Now it's going to test my internet connection because during the installation it's going to download some updates. So you see the thing is little spinning there, so I'm just waiting here. And now it says above the square it says this mirror location passed tests. So that's how I know okay, we are ready to go. Again, I'm tapping enter here. Here I'm also going to be tapping enter, but here you see in the screen there is an option that says encrypt your disk. Now I'm going to do something that I usually won't recommend, but what this is just a learning environment in a virtual machine, right? I'm not going to be storing any data.
-
When you install Linux on a server that you're going to use or when you are using it on a personal device, you must always always encrypt your disk. It's extremely important that you encrypt your disk. And that is because when someone gets access to the physical device, then you then that person can access all of your data. If you encrypt it, all of the data is just gibberish unless they have your encryption password, your decryption password. So normally for devices that you actually use, always encrypt your disk. However, in this case we are not going to encrypt it. So I'm just going to press the down arrow because we see it's blinking in the top. I'm just going to accept all of this. Just press the down arrow until I am in the bottom where it says done, where that is green. Then I'm going to click enter again, okay? I'm pressing enter again. This is all fine to me, okay? And now I'm pushing the down arrow and continue.
-
Enter. Now it wants my name. So I will just enter name. We are going to be just using the user. My server name is going to be Cato, c a t o. It doesn't really matter what you do, but this is the name that I'm using in this course. And as my username, I'm going to be very imaginative. I'm just going to pick user. And for my password, I'm going to pick a very secure password called password. Password. And I'm pressing the tab key to go to the next one. Password okay? And I'm pressing tab again and then done. So my my name is user. The server name is Kato. The username is user and my password is password. Now here I'm just going to tap enter, skip for now. Now here it's important that you stop and you follow along very very carefully.
-
You need to install Open SSH server, okay? So you see my cursor is blinking at the top there. If I press enter now, you see that an X comes into that box. This is what we want. We need to install Open SSH server for this to work, okay? So when I tap enter again, it's unchecking it. There's no X. When I tap enter, there is an X there, which means that Open SSH server is going to be installed. And this is what you want. This is extremely extremely important that you pay attention here and that you do this because if you do not do this, it will not work, okay? We have to install Open SSH server. So when there's an X there, then you know it's correct. We don't need to do anything else, just make sure the X is here. Then we are going to press done. Here we don't need any of this, so I'm just going to press down down down down down all the way to the bottom until the done section is green. And again, I'm pressing enter.
-
And now it's going to be installing my Ubuntu server. Now this is again going to take a few minutes and I'm just going to skip the video until this wizard. Okay, my installation is now finished and I see that because in the bottom it says reboot now, okay? That's how I see that I am now ready to finish this. So I'm just going to press the down arrow where reboot now is green and then I press enter to reboot. So now it's going to restart my server. And now it's saying oh failed and there are a few errors here. So then it's going to say please remove the medium and press enter. This is normal. So, you just press enter here now. And here we go. We have our login prompt. So now it's saying a few things here. Um First it says login and then it it printed out a few things like this is nothing to worry about. Uh now I just have to type my username.
-
So it's user. And then the password is password. And now I am logged in. Uh this is my my my Windows server or my my Linux server running on Windows. So congratulations. You have now successfully installed a Linux machine on your Windows machine. So this is working really well. And um now you see here that it says the IP address on the on the in the middle of my screen. But if you if you did not if you forgot your IP address or you need to get it later, then what you can do is you just type IP space A. So IP space A. That's all you need to do here. IPA. And then it's going to print out all of the network interfaces on your machine. And then here you will see this 192 168 126 129 um address listed here. On the top one, that's the loopback device. You can just ignore that for now. You have to look for something like ENS or EF0 something like that.
-
So now what we're going to do because this in in in VMware, this is a little bit clunky. We don't really want to be using this because what we're basically simulating is that we have a um virtual machine running in the cloud, right? Or we are at work and we have a rack of servers and now we want to connect to that server. And we're going to and that's and in in order to do that, you use something that's called SSH. And we're going to be doing a full deep dive on how that works later in this course. But for now, what I want you to do is I'm going, you're going to go to Google and then you're going to say W E Z T E R M Westterm. You're going to be downloading Westterm. So you click on that link and then here on in Westterm you go to download and then here it you can see that it's down you can download it for Windows, macOS or Linux. So this is why I recommend Westterm because if you start using this program and then you move to Linux or you go you're using on your macOS then you always have the same thing, you have the same configuration and it is a very nice program that works everywhere.
-
So this is the one that I recommend. So you click Windows and then you download it and then you install it. It's very easy. And now I'm going to just click my start menu and I'm going to type uh I'm I'm going to search for W E Z here. Oh the it it already started but let me see if I just do Westterm now. Here Westterm. Westterm app. I'm just going to click that and now I have my Westterm. This is my terminal emulator and now it's as if I am connecting to a different machine, right? So now I am going to again I'm going to take note if this IP address so 126129. So here what I'm going to type is SSH user at 192 168 dot and what was it?
-
126129 126 dot 129. And if I now type this now I'm going to create a connection to this server, right? So I'm just going to close this and now it's as if I am going to be connecting to this server even if I was at work or something like that or it's a machine running in the cloud. So, if I just do SSH user at [clears throat] and then the IP address, it is now going to say do you are you sure? And I'm going to type yes. And now it's asking me for my password. Well, in my case it is password. And now I am connected to my server. So, it says user at Kato. And I'm this is my Ubuntu server now. And this is it. This is what you need to have to in order to start the course. From here we can just start issuing commands. And now we have successfully created our server that we can use to do this course. Perfect.
-
Now it's really nice the nice way the nice thing of this is that you can actually create multiple of these, right? If you want to experiment more. So, how this works is here in the top right. If you now want to close this server, for example, you can go to power and then you do shutdown guest. And then just do shutdown. Now it's going to shut down the server so that it is safely powered off. And I can go here and right click and then I can do power on this virtual machine again, for example. And I can manage them from here. I can create multiple ones and now I have the ability to create servers and we can start working on our course now. So, I hope this was helpful and I will see you in the next module where we're going to be learning how to actually use our Linux server. In this module we're going to be setting up a virtual machine on macOS. Now I'm running this on a MacBook M2, so it's the silicon chips.
-
And if you're using the Intel one, then this this is also going to apply. But I'm very specifically doing this on a newer model MacBook. Like silicon chips have been around for a few years now. But there are some nuances to running virtual machines depending on what kind of MacBook you have. If you have a very old MacBook, you have an Intel processor, then everything is going to be pretty easy. If you have a M processor, M1, M2, 3, 4, 5, I don't know if 5 is there yet, but if you have one of those, then you need to have a different setup because it's a different processor, a different architecture. But it's all fixable, so that's fine. Um the program that we're going to be using for this is called VMware Fusion. So just like we do in the Windows module, um you have to install VMware Fusion.
-
That is the Mac version of basically VMware Workstation, although Workstation is has more functionality. But VMware Fusion is the way to run virtual machines on macOS. In order to do this, I'm going to be including a link below uh in there is a Reddit thread which I will link that points you to the right link. And basically you have to create an account and eventually you need to end up at this page here that says my dashboard, okay? So if you go to my dashboard and the URL here is Support my dashboard. Now in my dashboard, you go to my downloads. Oops, my downloads here. And in there there's this this button free downloads available here. So you click on that.
-
And then here you're going to search for uh VMware Fusion. Let me see. Here, VMware Fusion. You click that. And then you click the this one, the release. And you're going to click download here. You have to enter your details and then you get the download. So you get a dot damage file, dmg file file. You double click that and then you install VMware Fusion. It's very easy. Then when you have downloaded and installed VMware Fusion, then you're going to see something like this. The next step is that you're going to download Ubuntu Server. Now here it's important an important nuance here. If you have an Intel chip, an old MacBook, first of all you're just going to go to Ubuntu Server download. You just search for that and then you're going to get this get Ubuntu Server page. Okay?
-
Now the one that we're going to get is Ubuntu 24 LTS. That's the Ubuntu Server that we're going to get. Now here if you just click download, you're going to get the standard AMD 64 version that is used for Intel chips. So if you have an old MacBook, an old Mac machine with an Intel chip, then you download that one. If you have an MacBook with a which is a bit newer, which has an M 1 2 3 4 chip, then you go to Alternative Architectures and then you go to ARM and then you download that one, Ubuntu Server 24 for ARM. Okay? So you don't download Ubuntu Desktop, not Ubuntu Core or Cloud, Ubuntu Server for ARM. If you have a MacBook with a Silicon chip, an M 1 2 3 4 whatever, M 1 chip. Okay? So you download that one and that is a ISO file that you get.
-
Now when you've done that, then you can just start VMware Fusion and here it's going to say install from disk or image. So I'm just going to minimize this and then I 'm going to press command space and open my finder here. So here I will have my um ISO file here. And then I open I have this here, and then it wants me to drag the ISO file. So there is the ISO file here with ARM. And then I just drag that in here. Okay? Then I'm just going to click continue. And I'm just going to accept the default settings here. Just continue, finish. I'm This is not This name is fine. I'm going to click save. And this is going to start the server already. So here I'm just going to press enter. And now in the top right corner here, like I If I can now not move my mouse anymore, okay? In the top right corner, it says something like con control command to release. So if I press control command, now my mouse is back again.
-
But if I click inside here, my mouse is in the VM and now I'm controlling it. So if I now press my arrow keys, I can go up and down. So I'm going to go to English. And I'm going to press enter just to accept this. In the bottom of the screen, you see that the done thing is green. That means that I'm currently selected done. So I press enter. Here I'm going to again press enter. And now we see that we we I I'm going to verify that my IP address is shown here. So it says DHCP V4. And it gives me an IP address. And I'm going to write this down. 172 .16 .88 .129. Okay? I'm writing this down. It's very important that you pay attention and that you see that a number there as well. There's going to be some sort of number there. If if that's not there, something is wrong and then your VM won't have internet access.
-
You may have to try again or you have to look up a guide, but you must see a number there and I want you to write that down. Okay? So then now I am going to just press enter here. Again, I'm pressing enter. Now it's going to test the mirror, so it's just going to test if it can download any updates. And now you see in right above the square it says this mirror location passed tests. So that is what I want. I'm going to press enter again. Here I'm going to accept these file these defaults. Here it has an option to encrypt the the disk. Now I always recommend that you encrypt disks if you're going to be installing Linux on a laptop or a a machine that you're actually going to be using. This is a virtual machine that we're going to be using for testing and learning, so you don't have to encrypt this. But always always if you are using a Linux machine that you're actually going to be using like a laptop, you must always encrypt your drive. It's extremely important that you do that. But for this learning testing VM, we don't have to do that. So I'm just going to again press the down key all the way down and accept the defaults. Done.
-
I'm pressing enter again here, just accepting it. Now I'm pressing down again because I want to continue. I select continue and then I press enter. And now it's going to ask me for a few names. So my name I'm going to just use user. My server name I'm going to use Kato c a t o. It doesn't really matter what you call it, but in this in the course you are going to be seeing me use the word Kato. So if you want to do it exactly like I do, then you enter Kato here. Picking a username I'm just going to write user here. u s e r user. And my password's going to be very safe. p a s s w o r d password. Password. Password is my password, okay? Again, this is not safe, but I'm doing this in a virtual machine that I use for learning. Now we're pressing enter. This I'm going to just press enter again, accept the defaults. Now here, it's extremely, extremely important that you pay attention here. I want you to pay attention and follow exactly what I do.
-
In the screen now, it is asking me whether I want to install Open SSH server. It's extremely important that you do this. You must do this. So here I'm you see that the cursor is blinking right beside Open SSH server. Here I'm going to press enter and you see that an X appears in that box. That means that I'm going to be installing Open SSH server and this is what I want. If I press enter again, the X is gone and it will not install Open SSH server. This is what we not don't want. I want to install Open SSH server and this is extremely, extremely important that you do this. So I'm going to press enter and here I'm accepting as installing Open SSH server. I don't change anything else, but now I there's an X right beside install Open SSH server and this is what you want. It must look like this.
-
Then I press the down arrow key all the way and now you see that in the bottom of the screen it says done. That is now green. I'm going to say enter there. Now I'm going to again take the arrow key all the way down to the bottom and I'm just going to accept this. I'm not exiting anything, just going to done and pressing enter. Now my machine is going to install. This is going to take a minute, but when it is finished, then I will have my virtual machine. So let's give this a minute and then we'll be done. Okay, my server is now finished installing and I know this because it says reboot now in the bottom of the screen. That is how I know that it's finished. So I'm going to press the down key again and then I 'm going to select reboot now and I 'm going to press enter. And now it's saying please remove the installation media and press enter. That is completely fine. I 'm just going to press here. And now it's 's to reboot. And this is now going to start my fully installed new virtual machine of for Ubuntu Server.
-
So it's asking me for a login. So now I will type user. And then password. And here we go. I am now logged into my fresh Ubuntu server. Now this is then using the console, right? This is the the the VM console and we're going to be learning the difference between console and CLI and terminal in later in this course. But the main thing is that we don't want to be using this window to connect to our virtual machine. Because basically what we have mimicked now is that we have a server running somewhere. This could be in the cloud. This could be in a physical environment at work or something, but that is what we are simulating here. Now in order to connect to this server, we're going to use something that's called SSH. So I'm going to press command space. And I'm going to type terminal here. And I'm going to using the standard macOS terminal for this. And if I press command plus then it's going to be a little bit bigger, so it's a bit better for you to read here.
-
So now I have my terminal and what I'm going to type now is the is the IP address. Now if you have not written it down, you forgot to do that and you need to get that IP address, what you can do is you do I type IPA. So IP IP space A. This is going to show the IP address. So here you see in the top it says LO, which means your loopback device. That's the one that you don't want. But there's this NP2SO. And below that it says INET. And there it says the 172 88 etc. Okay? So if you lost your IP address or you forgot to write it down, then you can get it by typing IP space A. So I'm going to type here SSH and that is the that is how you connect to a different machine, SSH uh user at 172 dot 16 dot 88 dot 129.
-
And now it's going to ask me, hey, are you sure you want to connect to this? And I'm going to say yes. Now it's asking me for my password, which is password. And now boom, I'm connected to my server. So even though like this is not running here, but this can just now run in the background and this is now my interface to run well to to to run on my server. This is how I can now run commands. I can do things. I can do cat etc OS release. And now it says that oh we are running on Ubuntu server. So this is almost the same as if you were to rent a server or you start a server in the cloud and you connect to it. And this is why we do it this way through the terminal and by SSHing because this is what you this is exactly how you would do it at work as well. So you are learning and practicing these skills, right? So this is why I I I I strongly recommend that you use the terminal rather than the console. And now we can actually continue with the course.
-
Now the Mac terminal works fine. It is good, but if in the Windows course actually or the Windows module for this course where I show you how to install this on a Windows machine, I recommend that you download Wes term. So if you search for Wes term, here there's Wes term terminal emulator. This is a really nice one because this one will work on Windows, Mac, Linux everywhere. So if you want to have a bit of a nicer, better one, then I recommend that you download Wes term. It's very easy. You just click download and you download from Mac OS and you install it. But if you just want to use the the terminal here, this is also fine. You don't need anything fancy. You just need a place to run commands. All right. Now you have a virtual machine running on Mac OS and you're ready to continue with the course. All right. So we have a Raspberry Pi and now it's time to install Linux on there. So the way I'm going to do that and as I mentioned in the introduction is I am going to recommend that you use a SD card.
-
So this is my little SD card. It's a 64 gigabyte SD card from Amazon Basics and I have this USB SD card reader. So I just put this in it and it clicks into place and with this I can either enter it in a USB C port or a normal USB port. So I have my my SD card here and I am going to be putting this into my workstation here. In order to get the we need to install the operating system, Linux, on the SD card. And for the Raspberry Pi, there is a very convenient tool available. You go to raspberrypi.com/software and here I I'm running this on Linux, so I'm seeing download for Linux. There's also a download for Windows or a download for Mac OS. So it's available for everything and you download the program and then you run it. So when I am I I have it running on my computer now and this is what I see. So I am now going to put this into my workstation.
-
It is now connected to my workstation and then I'm going to choose my device. Now this is of course going to be dependent on which one you have bought. I recommend getting a Raspberry Pi 5 and that is what I'm have what I have as well. So choose the one that you bought. Then it's time to choose the operating system. Now, there are a few options here. The the main one here is Raspberry Pi OS. And this is a an OS which is based on Linux Debian. And this one is a actually a fully operation fully functional operating system with a graphical user interface. So you will get a desktop environment and everything works out of the box. What I recommend is that you um do not install this yet, but we just continue with Ubuntu Server that we're going to do. But after you finish this course, I highly recommend you just take your USB again, install Raspberry Pi OS on it and check out the differences.
-
But on this course is focused on the command line and therefore we want to keep it as minimal as possible. So what we're going to get is the other general purpose OS. Click on that. And then we're going to click on Ubuntu. And then Ubuntu is going to show us several options here. So there's Ubuntu Desktop and Ubuntu Server. Now in the in the introduction, I've talked about in which one we're going to install. And in our case, we're going to be getting the Ubuntu Server 24 LTS or whatever LTS version that you have available when you're watching this course. Doesn't really matter which one if you get the the the latest the like the Ubuntu Server 25 or 24. I don't expect there's going to be much differences there, but you can't go wrong with the LTS. So we're going to pick Ubuntu Server LTS. This is then going to download the correct image for us already and make a few Raspberry Pi specific changes in the configuration that we need in for this in order to run on a Raspberry Pi.
-
Then we're going to choose the storage. So this is going to show the storage that you are that you just attached. Now I know for a fact that my drive is 64 GB. I just showed you that. So therefore, I know that this is the right one. And then I'm going to click next and then it's going to ask me, would you like to apply OS customization settings? And yes, we're going to do that. So you click the edit settings button. And then you're going to set your hostname to Kato or whatever you want. Like I'm using Kato. And then we set the username and password. So my user is going to be um Misha. And my password Well, like I'm actually going to do user and then my password is going to be password. Here you can set up a wireless uh Wi-Fi connection. So if you don't have a wired connection to your Raspberry Pi, you can just set your wireless here, your your Wi-Fi if your Raspberry Pi supports that, of course.
-
But make sure that you do it correctly, that the name is correct, so the SSID, so the name of your Wi-Fi network and your password are you're absolutely sure it's correct because if you are running it without a screen, it's going to be connecting it for you and you there's no way for you to change it or to interact with it if you don't have a screen and a keyboard connected to it, right? So you can actually do this completely headless, so without any screen attached to it if you just configure the wireless LAN or if you just um if you connect connect it up with a wire. Now I am not going to do that because I connected with a wire. My user is user, my password is password, and to be clear, you should never do this in a real system, but for the course I'm just doing it. Set locale settings is not not required, but it's nice to see that the correct time. So I'm going to do the Europe Amsterdam because that's where I am and the keyboard layout US.
-
Now in the services tab, by default this is going to be turned off. You're going to be turning on SSH. Enable SSH and then use password authentication. You We're not going to use a a key yet. We're going to be configuring that later. Now we just want to get something up and running and connect to it as fast as possible. So enable SSH and use password authentication and in future modules we're going to go deep into what SSH means and why you should actually not use password authentication, but at this stage this is what you're going to do. Enable SSH, use password authentication. And then further options, you can eject the media when finished, play a sound when finished. Uh I recommend not enabling telemetry and those are the options we want. So hostname user password locale, service, enable SSH, use password authentication, and you This doesn't really matter. Save.
-
And I want to apply these settings. This will be erased and now it's asking me for my password, so I'll enter that. And now it is writing the new OS to the SD card. And because I have already cached this into my Because I already downloaded the image, this is going pretty fast, but it When you're doing this on your PC it might take a little while. And another thing is if you're running this on macOS or Linux, I'm not sure if this is going to happen on Windows, but if you're running this, like you will now see that it is writing and it's stuck on writing 99%. Now this is due to a bug in the Raspberry Pi installation where the the program is actually it's writing the the installation to memory. And what's happening now is it it now it is writing it to disk. So it is now It's stuck at 99% but the last 1% is doing the actual operation of writing it to the disk and it's like 1 gigabytes or something. So it can take a lot a bit of time depending on the speed of your USB etc.
-
So you see that it's already taking a couple of minutes now and this is completely normal. So when this happens just give it some time. When it's stuck at 99% don't cancel it. You see now now it's verifying. So just be patient. If it's stuck at 99% it's a bug in the installation program. You did nothing wrong. So it's now verifying. It's going to check if everything was written to the disk as we expected to. All right. It is now written and I can now remove the SD card from the reader. Cool. So what I'm going to do now is I'm going to open OBS and you will see that behind me I have a little rack standing. Now my Raspberry Pi is actually running inside of that rack. And what I'm going to do is I'm going to take my USB stick, insert it there and I actually also have a little screen and you can see it boot up. So I'm not able to talk it to the microphone as I do this but you will you will see what's going on. So I'm now taking the USB out of it, inserting it to the the Pi starting it up and then I'll get back to you.
-
Okay, so I've now inserted it and now we see that the screen is showing some data. So it is now booting itself up and this is completely normal to see so much text and it takes a little bit of time. Okay, so you can't see it but it is now prompting me to log in. So it's going to say Raspberry Pi log in, username log in. So I have a keyboard here. And with that keyboard, I am able to manipulate the Raspberry Pi directly. It is actually going to restart because it has installed a few things automatically. Okay, so now that I have a screen, I can get my IP address. So, the way I'm going to do that is I'm going to just log in with user password.
-
And then I'm going to type the IPA command. So, I know now that my address is 100.240 and you can check out the virtual machine modules to see this other process where I am actually doing it on the screen that may be a little bit clearer for you. But all you need is to get the IP address, right? So, now I have the IP address. So, in my case it's going to be 192.168.100.240. That is the IP address that I have. So, what I do now in my terminal, I will write SSH user at 192.168. .100.240. That is going to ask me the authenticity is not established. So, I have not connected to this before. Are you sure you want to connect? Yes.
-
And now it's prompting me for the password. So, for me it's password. And I'm in. You see here, this is the Ubuntu server. So, now I'm logged in to my fresh Raspberry Pi Ubuntu server. But this terminal that you see here that needs to be available on your system, right? And in the in the modules about creating virtual machine on either Windows or macOS, there's going to be instructions on to actually get this place where you just ran where where you should be running this SSH command. This command that we just ran SSH user at IP address. So in those modules I I explain how you can get that terminal on either Windows and Mac OS and how to make your first SSH connection. So if you have your Raspberry Pi up and whether you've connected it to a screen or not um you should go back to those modules and see how I connect to the virtual machine because there's fundamentally no difference between connecting to a virtual machine or your Raspberry Pi in that sense. So what you need is to get your IP address and have a place to run the SSH command from and that is explained in those modules. So depending on where you are running this on
-
go to those modules and review how to get this terminal and when you have done this first terminal setup and you're able to run SSH user at and you do password and you are now connected to your new machine and you see user at Cato and whatever username you have selected this is the point where you can stop this video and then move on to the next module. Just a quick note on how I suggest you go through this course. So you open up the classroom like this and then you have your video like this and then I recommend you position your terminal on the right-hand side and go through the commands like this because in the in the course the text that you see me using in this course is going to be included with the modules. As you in this course you will see me you know using this and also having this window below here or switching to a second one like this and for now don't worry about me switching around like this like I want advanced users so I do this blindly with just my keyboard.
-
Um you're going to be learning more about this in the course as well, but just note that I am running my documentation here and then I'm executing those commands in this one below. Now what I recommend you do is you have your course open and then your notes will be down here in the bottom and then you run those commands in your command in your terminal like this and then keeping them side by side. So it's very important that during this entire course you are actually running these commands with me. You have to get hands on. Don't just watch this on your phone while sitting in a chair. Have your screen open like this with a terminal window on the side and do it as I am entering the commands as well. Do it with me. And if I go too fast, rewind and do it again. But you have to start typing these commands in the terminal as fast as possible. That being said, let's jump in. Real quick, before you enter your first command, do you want to finish this course and actually remember it? Do it alongside 10,000 people in our free Linux community. You follow the course module by module, you track your progress and you can work through the hands-on workbook and you can ask for help when you're stuck. It's free at cubecraft.dev/linux.
-
The link is in the description below. All right, let's start. All right, congratulations. You now have your Linux server. You're able to connect to it and now we can actually start working with our server. So in this new window, I'm going to SSH into my server on my Raspberry Pi. If I can enter my password correctly. Okay, here we go. So now I am on my server. I am connected to it as user at Kato and now I can start running some commands. So what you see here is I have the the course documentation open in the top here And in the bottom here is my my my shell, my connection to my server. And I'm going to be explaining all of the details about how you can do this, split the windows, etc., further on in the course. now you can actually see what is going on and how I am navigating around. So let's do the first few commands. So the first command that we're going to run is who am I?
-
What is the current user that is logged in? And in this case, it's user because that is the the user that I configured in the Raspberry Pi imager. And then I used that in my SSH command, user at IP address to connect to my server. Then what machine is this? That's going to be hostname. And that is also the same that we configured in the Raspberry Pi imager. And you also see this in this line here, which is called the prompt. And we're going to be getting into what that actually means a little bit later. But you see here that I am user at Kato. And these are our first commands that we have run. Next, we can check out where we are. So let's do the the next command that we're going to learn is pwd. Where am I on the system? And this is pwd stands for print working directly directory. And this shows you your current location.
-
And the file system is something that is get it takes a little bit getting used to if you're used to Windows. But this is how you can at least see where you are currently. And we're going to be learning about navigation in the next few modules. The next one is going to be LS. So the LS command together with pwd is probably what some of the commands that you're going to be running the most. So the LS command, it shows it lists the folders and the files in your current directory. So if I do LS here, I see that my home user directory currently does not contain any directories. But if I do ls and then forward slash, then we see that we get a little bit more. And these are some very strange names, boot, etc, media. And we're going to get into what all of this means in in a second. But running the ls command means list the current directory or you can say ls slash or slash here you see a bunch of directories. So, let's do ls slash etc.
-
And now you see the contents of the slash etc directory. So, ls is for listing listing directories and files. Next, we're going to learn the date command. So, when you do date, it's going to show us the current time. So, when I'm recording this, it's Saturday, 13th of December, 8:00 a.m. So, date is very useful. It's also very useful to use in scripts and programs which we're going to be getting into later in the course as well. But now our screen is pretty messy, right? We have a bunch of directories there, but maybe we want to get a nice clean start again. And the command you can use for that is clear. So, now our our our terminal is nice and clean. So, I can do a pwd again, home user. I can ls here. Oh, there's nothing in here. So, let's do an ls root ls slash.
-
There is a little bit more there, but and let's check out what time it is. It's now Saturday, the 13th of December and 8:12 a.m. Now, this is pretty ugly. So, let us go and clear the screen. And congratulations, you have now run your first commands on the Linux command line on a Linux server. Now, you You the the commands that we have done, and then there is a challenge here for you. Go to your terminal, and then you type exit. And now I am logged out again. And what you're going to do is you're going to connect, reconnect to your server and run these commands and play play around a bit with them. And when you've done that, you can move on to the next module. All right, you've connected to your Linux server and run your first commands. Now, before moving on, try this. Disconnect from your server, reconnect, and run those same six commands again without looking at the video. That's the first exercise in the free Linux workbook. You'll find exercises like this throughout the course with solutions to check your work. Download it free inside our free Linux community. The first link in the description below. Now let's continue.
-
So now we have our system running. We are able to log in. And now we can continue with our exploration. But in this module, we're going to be addressing a few questions. First of all, like what is Linux? And what is a shell? What is actually going on here? So I'm going to this module is going to be a little bit more theory heavy, but it is very important for your understanding um of the Linux operating system. But before we get into the theory, let's just run a few more commands. So if you haven't SSH'd yet, you can SSH back into your system, and then we're going to run a few more commands. The first of them being echo hello world. So here we go. So the the echo command simply takes some input and then prints that back out to the terminal. Now this might seem a very useless command. So echo my name is Misha. Like who who is ever going to do that?
-
Well, what it it is a very useful command to use in scripts, for example. And I'm going to be getting a little bit into this later in this module. But in the scripts you can like output things to the command line, and you can also use this um in pipes. So when for redirection and we're going to be learning about that in due time as well. So it does have a lot of functionality. Now let's check out what is the actual system that we are running in. So if we do cat etc os release, let's let's dissect that command a little bit before I run it. So cat cat is the actual command, the command that we're running, and then we are giving it a file. So etc os release. So if we do ls etc and if I then take a look here, then I should see here os release.
-
So we remember the ls command, ls etc that lists the contents of the etc directory. And here I see os release. Now if I do cat, I am running the command and I'm pointing that to etc os release, which is a file. And the content of that file is now being printed out to the terminal by the cat command. That is what cat does. So cat is showing us the content of the etc os release file. And in this case the content is the pretty name is Ubuntu 24. The name is Ubuntu, and this is the version that we are running. Then there it contains some information about the Ubuntu distribution, but that's it. So with this command cat etc os release, you can very quickly figure out oh what is actually running here. So you don't need to do this, but if I just do a podman run Alpine, I'm podman run IT Alpine. But like don't you don't have to pay attention to this, but I'm just showing you I'm now in a different environment. If I do cat at see os release, then I see that I'm now in a container that is running Alpine Linux. So you're going to be learning about this later, but I'm just showing you like there's different types of Linux
-
and you can figure out the type that you're currently running by running the command cat at see os release. The next command is going to be uptime. So how long has this system been running? And our my current system has been running for 34 minutes. Like it's 34 minutes that I installed Ubuntu on that Raspberry Pi and that is now running. So this way you can see the uptime. If I run this on my host system, we see that this current system has been up for 5 days. Now let's do something else. So earlier we saw that our home directory, so if I do clear again and PWD, I am now in my home user directory. This is called your home directory and if I now if I now run LS, we see that there's nothing in there. Now how would we if we just want to create a simple file, we can do touch my file dot txt.
-
And if I now do LS, now I see that my directory contains a file called my file dot txt. So touch is a command to quickly create an empty file. But an empty file is not very useful, so let's just remove that file and you can do that with the RM command my file. And if I now run LS, we see that the the file is gone. Now one note about the RM command, you may be used to right if you're on Mac OS or Windows and you delete a file, you put it to the trash bin or the recycle bin or you get all sorts of prompts saying, oh, are you absolutely sure that you want to delete this file? And are you completely sure of this? There's not so much hand-holding on Linux. So one example being the RM command, you saw I just typed RM myfile.txt and it was gone.
-
And that I I personally love that that I don't have to constantly, yes, I'm sure. This is why I love Linux so much because you get the full control over your operating system. However, it also means that you need to use these commands responsibly. And especially the RM command, you really have to think twice before you press enter on that command. The next command we're going to learn is the history command. So if I clear this and if I type history it is going to show me all of the commands that I have run so far. You see, I ran the echo hello world, the OS release, the clear, etc. So history can show you exactly all of the commands that you have run. Now as we are doing this, let's take a step back and and reflect on what we're actually been doing. So if you're I'm I'm running this on a Raspberry Pi, so I have the physical little server running behind me.
-
But if you did this on a virtual machine then this is you you must understand this is a complete computer. So it has its own CPU, its memory, it disk and network connection and it runs inside of your main computer. And in the VM you can break things, you can delete everything and start over. The same is for the Raspberry Pi. You can literally just break everything on this Pi and this is the concept of a home lab, right? A laboratory where you can experiment. You can run experiments, break things. So never be afraid of running a command and wondering what it's going to do or not being sure about what it's going to do. That is what have these practice stations for. So, you can you have to cultivate this because when I started out, I was really scared to touch things and I was like, oh, am I sure I'm I'm not sure if I should run this. Well, don't be scared of running things. Don't be scared of breaking things. That's why we use a virtual machine or a separate machine.
-
Now, what happened? So, when we went in our command line, whether you are in Windows or whatever, you type the command SSH at IP address. So here, the command is SSH user at 192 100 . 71. I changed my IP address. So what this does is it establishes an connection to this computer and then everything you type in that shell, in that terminal session is being sent to that computer. It gets executed there and then the results come back to your screen. So this is this is how the real system administration works. Your server could be in the cloud, in Germany or in the America, but this is how you manage servers over the network. And [snorts] when you run SSH user at 192, you're you're running the SSH command on your local machine telling it to connect as user at an IP address. Now, what is an IP address?
-
And and [snorts] like this the like networking is out of scope for this particular course. We're going to do SSH later in a later module, but fundamentally now it's important to understand what a IP address is. So in your house, there is going to be this little device with all of these blinking lights that you got from your internet service provider that is called a router. Now, your router is going to This is your house. House. And your router is going to create what is called a network. And a network is simply a place where computers can connect with each other. So in your network you have your iPhone and then you have your laptop, laptop, and maybe a few other devices. Maybe your brother has a laptop. And all of those are connecting to the router usually over Wi-Fi in your home, right?
-
Wi-Fi. So you When you buy a new laptop, you open it up and then you type the password to your Wi-Fi and because it's um because you are selecting that Wi-Fi from the little drop down, that's how you know that you're connecting to your router, right? And when you have authenticated to that router, this router is going to give you an IP address. So an IP address like this An IP address is simply the address of your device on the network. So you can see this as the number on your house. So when you receive a package in the mail, the mailman is out there on the street and he's looking for the right place to to um knock on the door. And it's He is going to look at the number on your house. So you have your street name and then the number on your house. Well, an IP address is very similar to that.
-
So when when in our case we are now Let's say we have this laptop and then we also have our little Raspberry Pi. So in the case that I'm running it, I have it on my Raspberry Pi. And then it has an IP address. In my case, it's 71. So if I now type this command, SSH and then um I say user at this IP address, what's going to happen is that the laptop is going to talk to the router and it's going to say, hello, I would like to establish an SSH connection to this number. And then the router is going to first of all look at, hey, do I have that um connection? Do I have that IP address in my my address book? And so and we'll say, oh yes, I have that.
-
So I will connect you to this one. It's like the old telephone operators like you should be back in the day when you made a phone call, you would actually call some you would like ring somewhere and then there would be a woman there, usually a woman, asking you who do you want to call? And then they would say, I want to call so and so and then they would physically connect a wire to the in the console and connect you to the correct person. Now this is basically what the router is doing. So you're saying, I want to connect to this number and then you are connecting to that number. When you are running a virtual machine, however, we have configured it in bridge mode and then it's a little bit different because then this Pi like I see if you are running a Raspberry Pi, it's now a VM and it has a and and it has a different IP.
-
Now when this laptop is connecting to it, when you say, I want to connect to this IP address, please, it's actually not looking at the router. It's actually going to look at the the VM directly. And yeah, there's a lot of nuances. It's not exactly correct what I just told you, but for the purposes of this course and the level where you are at now, you can just say that the laptop knows where the virtual machine is, and therefore it does not need to talk to the the larger network. So now the the the virtual machine is so now either you have your Pi on your network or you have your virtual machine. You are requesting an IP address or a connection to an IP address and you have been granted that connection. And when that when that happens, so I do SSH user at that, then this device is going to respond.
-
So I'm saying hello, I would like to connect over SSH to you. And then on that device, in your virtual machine or your Pi, there is now running an SSH server. And SSH is connecting over a certain protocol. So your your your device is getting a request to that server and it knows what to answer. So it is now saying, hey, okay, sure, I'm accepting your connection, but before we I let you in, you have to tell me your password. So this output is coming from my Raspberry Pi. This is not running on my computer. This is running on the Raspberry Pi. So I do password. Here we go. And now I'm connected to my to my Raspberry Pi. So now every time I run a command here, that is happening on the Raspberry Pi. So that is what's happening that that is what's happening there. But what is it that we are typing into?
-
So how does this come about, right? How how is it that I can now sit on this workstation and type stuff and then it's happening on that machine? How does does work? Well, let's get into that. So this fundamentally goes back to what is Linux. So when your VM is running or your your Raspberry Pi, there is a program called the kernel that is in charge of everything. So the kernel controls the hardware, so that your your CPU, your central processing unit, your memory, your disk, your network, that is all um managed by the kernel. It also manages your files, it runs programs, and it keeps track of the users and permissions. So when we ask the question, what is Linux, the Linux kernel is Linux. And everything else is just running programs on top of the kernel.
-
So the the thing is you cannot talk to the kernel directly. The kernel doesn't understand if you type show me my files or run this program. It it speaks a different language. It's a low-level language called system calls that the programs know how to use. So the the a nice image of this is this. So you have your hardware and in a virtual machine, this is your the the virtual machine is the hardware. Or in my case of my Raspberry Pi, the Pi is my hardware and in the Pi there is a disk, in this case an SD card, there's a Wi-Fi controller, etc. That is all the hardware. Now the Linux kernel talks directly to the hardware. The the Linux kernel manipulates the hardware. But in order to talk to the kernel, we need something else and that is called the shell.
-
And that is where the next section comes in. What is a shell? So there is a gap. We need we want to talk we fundamentally we want to talk to the hardware, right? We want to say we want to run stuff on our computer that needs to be done on the hardware. If we want to write a file to our disk, we have a request for to work with the hardware, right? We say, I want to do something with this hardware. Now, we know that the Linux kernel manages this, but we cannot talk to the kernel directly. The kernel is not a user interface. And in order for me to talk to the kernel, we need a layer in between there, and that is the shell. The shell is the layer between me or applications and the kernel. So the the Linux kernel is what is Linux, but in order to talk to the kernel, I need a shell. And I'm repeating myself often, but it's very important that you understand this properly. So take your time.
-
The shell is the program that bridges the gap between the user and the kernel. It's a translator between you and the operating system. So the shell presents you with a prompt. It accepts human readable format. It translates that into actions that the kernel can perform, and then it shows you the results. So when you when you type ls, you're not talking to Linux. You are talking to Bash, which is your current shell. Which means like when I'm typing ls, I am again, I'm not talking to the kernel. I'm talking to a program that is called Bash. This Bash program understands what I mean. So what I mean. So if I type ls here, Bash is going to find the ls program and ask the kernel to run it and then show me what comes back.
-
If I do echo hello world, then Bash is looking for the program echo and then asks the kernel to please run this program with the argument hello world. And then the result from that is printed to you to the screen. It show that that is also handled by Bash. Now how does the shell get here, right? So when your Linux machine boots the kernel loads and initializes the initializes the hardware. It then starts the first process called init or in this case systemd. And that process starts all the system services, the networking, the logging, and the SSH server. And we're going to get deeper into this in the processes module. But when you SSH into the machine, like I said, the the SSH server accepts your connection, it verifies your password, and then it starts the shell. It's a new Bash process just for this session.
-
So when I SSH Bash is started by the SSH server. That's it. So the shell is just a program that got started when you logged in. It's sitting there waiting for your commands. And when I type exit or close the connection, that process ends. So again, I'm going to SSH into you can see this happening in real time. Like you you don't have to know this, but I'm just going to run the ps aux grep SSH command and this is all going to get clear to you later. But now we see that there is one process called user priv that is actually that is the process that is accepting these connections. Now if I open a new terminal and if I then connect to it and if I now run ps aux grep SSH again, we see that there is a second one. So there is user priv here and there's user priv here. So there are two SSH processes running.
-
And this means that this process is now accepting commands. I can run LS, I can run cat, etc. That is all running. Now if I now exit this again, if I now run PS aux grep SSH, we see that there's only one SSH user priv running. So use SSH, it starts a process and this is a bash process for your SSH session. So that is what's happening. You you SSH, a shell is started for you, and that shell is the place where you can run commands and talk to the kernel. So when I type LS, bash is going to find the program LS or or let's do echo. So if if I run echo, bash is going to first find the command echo and then tell the kernel to run that. Now we can also check out the the location of echo. So if I do which echo, then we see that echo is simply located at user bin echo. So when I type echo, then bash is going to first look at a where is echo. Oh, there it is.
-
Please Mr. Kernel, can you please run the echo command with hello world for me? And it does that, then the kernel returns something and bash prints that out to the terminal here. That is fundamentally what is happening. Now the shell does more than just run programs. It can also transform your input before executing it. So if we do this, name is Linux. And if I then now do echo name, we can see that there it prints out Linux. So yeah, this is this is a little bit more advanced and we're going to get this in into this in the bash scripting course, but this is what I 'm doing is I'm setting a variable, and then Bash is able to interpret that variable for me. So Bash is a It's not just running commands. Bash is actually a programming language. And this is one of the biggest the biggest unlocks for me, and I got this from RWX Rob. He is one of my mentors. Unfortunately, he is not teaching anymore.
-
And But he is a great man. And I'm going to be mentioning him a lot in this course, actually. But the The thing here is that Bash Running Bash commands, so working on the command line like this, if I'm running LS, if I'm running Echo, fundamentally, what I'm doing is coding. Working on the command line is coding. You are working with a programming language that's able to do functions, variables, etc. So, learning the Linux command line is not just learning Linux. It's also learning how to program. You By running LS, Echo, you are already programming. If you just put all of these in a in a file, that is that is a script. You can string these together, and that's a script, and that's a program.
-
So, you are already You are You are actually programming while you're doing this. So, the shell is not just something to run programs. It's a full-on programming language. Now, there are different types of shells. So, there Now, we are running the the Bash shell. And this is the default on most Linux systems. Then there is Zsh. There is a fish shell. There's new shell. There's all sorts of different shells that can be run on a system. But yeah, there is a whole I can do a whole one-hour video on which shell to use, but the short answer is Bash. When you're starting out learning Linux, and if you want to become a DevOps engineer, you must learn how to uh work with Bash properly. And it's very important that you run Bash everywhere.
-
So when you buy a MacBook and you install it, if you then um run actually let's learn how we can um how we can find out what shell is currently running, we now are going to run the echo command and instead of doing the name variable that we were using before, there is actually a variable called shell. And this shell is this variable is handled for you on a system level. You don't have to set that yourself. But this this variable contains the shell that you are currently running. And lo and behold, in this case it's been Bash. If I would run a Podman Podman run IT Fedora. If I would if I'm running a I'm now and again you don't have to know this, but I'm now running a different Fedora a different Linux container. If I do echo shell here, we see that it's been Bash.
-
So all of the Linux systems that you're going to be running working on as a system administrator, as a DevOps engineer, they will all run Bash. That is the default. And therefore you do not want to get used to Zsh in the beginning because Zsh does a few things differently than Bash. And you have to if you are a carpenter and you are going to learn how to make furniture, then you have to make sure that you're using the right tools. You are not going to be made If someone who creates furniture needs different tools than someone who is building a ship, for example. Those are they're they're both carpenters, but they both have different toolsets. And Zsh does things differently than Bash. So if you are going to be a DevOps engineer or a Linux system administrator, you must use Bash as your only shell for at least the first year is my is my opinion. So if you're running on Mac, try to like you can do this. You can change your default shell to Bash and just use Bash for at least a year because it's going to help you in your development as an engineer. And that is all I'm going to say about it.
-
Bash is is what runs everywhere. You should learn Bash properly first. Now we have we've talked about what Linux is, the kernel and the shell, but there's this thing called the terminal as well. So what is the difference between the terminal and the shell? And this gets very confusing. So the terminal is the window, the the application that displays the text and accepts the the keyboard input. So if you're running this on Windows, you have been instructed to use Windows Terminal or West Term, actually. That is actually the number one. Windows Terminal. The macOS had on macOS there is this terminal app. There's iTerm too. Maybe you're just run using the VMware console window. I am this what I'm running on this system is Alacritty. These are all what's called terminal emulators. So a terminal historically was a machine the VT100 was a very popular terminal.
-
And to be clear, I am not old enough to have been running with this. As you can see, the release date of this machine was 1978. But this how people used to interact with computers. It's a terminal. Because you see in the old days, like now we have computers, everyone has their own computer. Everyone has laptops. You can even have servers at home with your Pi. So it's now very normal to have your own computer and the you may may have never thought about it, but the term PC you maybe refer to your PC, it's called a personal computer. And that at one point in history was a novel concept. You see back in the day computers were not something personal. It was impossible to own your own computer. The first computers were extremely expensive machines which took up entire rooms. So the only way you could access a computer was, for example, at university because your university had a computer or you would work at a big enterprise and the enterprise would have a computer.
-
Now this computer would be one big machine that many different people were using. There was no such thing as having your own computer. There was just this massive computer where all of these users are are computing on. But you they needed a way of connecting to that computer and that is what this this device is invented for, called a terminal. So even though this might look like an old computer, what we understand as a computer but fundamentally this device does is is only sending commands to the computer. So this is not a computer, it's a terminal. So to explain this you would have your university and in the university there would one massive computer, like one huge device.
-
This is your big computer. And you would have many different users who needed to connect to that computer because there was no personal computer. There were multiple people um sharing that computer. And in order to talk to that computer, you needed a device called a terminal. Like this. So the user then sits behind his desk and enters commands into the terminal and the terminal is then sending that to the computer through the the shell. On the computer a shell is running that is then talking to the kernel. So let's move this over. So this this user has a shell.
-
The computer then talks to the kernel and then the kernel gives the answer and this is then returned to the terminal and then then back to the user. This terminal device does not do any computing or did not do any computing. It's only connecting. It's sending keystrokes to the shell and this this device was capable of connecting but it did not do any processing on the device. That is very important. The actual processing, the running of the hardware is done on the computer, not the terminal. Now what is interesting is that now basically what's happening is that I have this you will have this program called Westterm, for example, or or whatever one of you you're your Mac, your your Mac terminal app.
-
This fundamentally replaces the terminal. So what this is called is a terminal emulator. These programs, Westterm, Mac Terminal app is called a terminal emulator. So the the program you see here, this thing with black screen on it and where I can run commands, this is called a terminal emulator. So it's nothing it's nothing else. It's it's just as if I am taking a machine like that, a terminal, and taking a wire and connecting that to my Raspberry Pi. Actually don't even know if it it's still possible, but fundamentally this is what happening. So this terminal emulator is already running on a computer. So it's as if I'm typing into that device. And now this terminal emulator is now going to talk to, in this case, a virtual machine on the device or my Raspberry Pi.
-
And that's it. That's exactly the same thing that's happening. So that is the difference between a terminal and and a shell. So the the the terminal is the the thing in in in the old days, the device, in our case the terminal emulator, that is able to show us the output of the shell. Okay? So that is the difference between a shell and a terminal. The terminal is just showing what the shell provides. The shell is the actual process on the computer. The shell is the program running inside the terminal that interprets your command. The terminal is the window. The shell is what is running in that window. And now there's one more term that we have to define, and that is called the CLI. So, this course is called Linux command line fundamentals. But what is what is the command line?
-
Well, the CLI stands for command line interface. So, this is the text-based way of interacting with computers. You type commands and you get text output. So, this is the the old way. The This is how people like before This is why Windows was revolutionary or like Mac was doing the same thing. But when Yeah, well, Windows became popular to the general public, this was a revolution because up until this point, people were Like this is a bit more nuanced that I'm saying now because there were different graphical user interfaces. But up until this point, the only way people could interact with the computer was through this terminal. In other words, typing commands and getting them returned. Now, when Windows came along, you now had a screen with your files on it and you could run programs on on uh on the screen. So, instead of typing commands, you're moving things around with your mouse and everything. Now, that is called a graphical user interface, a GUI.
-
So, the old days This is the command line interface where you're typing text and you're getting text back. And this, what you're seeing now here, is the graphical user interface where I have my my graphical programs. I can have my web browser. I can do many different things on this graphical interface. I can open my file explorer on this graphical user interface. This is all graphical. But like this is the exact same thing. So, I can open my home directory in this file explorer. This is accessing my home directory through the GUI, the graphical user interface. But the equivalent of this, so if I want to see what is in my home directory, what I do is I do LS. And here I see output, public, pictures. If I go back, uh I see output, public, pictures.
-
You see? So here I'm doing the same action. I'm seeing what is in my home directory. I'm doing the same action in both of these windows, but here I'm doing that through the CLI, the command line interface. And here I'm doing that through the graphical user interface. And then finally there is the prompt. So when you see this, this is your prompt. It tells you, like we saw earlier, it tells you who you are, the username, the hostname, and where you are. So here this prompt is telling us that we are in the home directory. And finally this is telling us that we are a normal user. So this is the prompt. It is the user, the hostname, where I am, and what type of user I am. So if I go to root, it will show me here. If I go to CD at C, it will show me that my uh that I am in at C, etc.
-
If I go to var, I'm in var. So the this is what the prompt is showing me. If I and we're going to learn about this, but if I change to the root user, then you see that this changes. So this is a normal user, and this is indicating that I'm now a root user. And that is the prompt. So how let let's just do a little bit of history of Linux now that we went into terminals and everything. So now you know what Linux is. It's the kernel and you're running a shell and how that is growing. So let's very briefly just do what what what what where it came from. So in 1969 Unix was created. So AT&T Bell Labs created Unix. It was designed to be a simple and portable operating system. So many of the commands that we are running now, ls, cat, rm, come directly from Unix. And Unix was the operating system that allowed people to interact with their computer. So these big these big computers that I was talking to that were running these terminals, they were running very often they were running the Unix operating system. And there are a few more like Solaris and that kind of thing, these old older operating systems. But that was called Unix.
-
Now in 1991, a man called Linus Torvalds, a Finnish student, created Linux as a free alternative to Unix. Because he was a student and he wanted to he wanted to use Unix. He was a computer science student. And but Unix was an professional software. It cost thousands of dollars. So you could not just use Unix as a normal person. There was something called Minix, but this was then very restricted. And Linus, he wanted to to learn how to talk to the hardware. He was interested in that. Instead of using Minix, he decided, well, let's just make my own Unix. Let's make my own operating system. And this is how Linux was born. So he famously made a Linux original announcement on something called Usenet.
-
And you can dive deep into the the history yourself, but there is a great article here on Wikipedia. But here is his original announcement. Hello there everybody using Minix. I'm doing a free operating system just a hobby. Won't be big A professional like Gu to clone AT&T. This has been brewing since April, starting to get ready. And here's he basically showing that he created this. So he basically rewrote Minix in his own thing and he called that Linux. Well, he didn't call it Linux over here as you see here in the the Linux Torvalds. He he actually wanted to call it Freaks, but eventually it was called to Linux. It was it was named Linux. So now from a student that created his own operating system, this has evolved to something that fundamentally runs the world. So most web servers run Linux. So when you visit websites, it's very highly likely that you're running talking to a Linux server.
-
Android phones run Linux. All of the cloud platforms, AWS, Google Cloud, Azure are running on Linux. Containers, Docker containers runs on Linux. Your TVs, your router, your IoT devices, all of that runs Linux. So Linux powers the world and that is why you need to learn it. So why Linux for DevOps? So if you are if you purchase this course from me, then it's very likely that you are interested in DevOps or becoming a DevOps engineer. And this it's important to understand why Linux is so important for DevOps. Well, again, all of the stuff that you're going to be working with as a DevOps engineer is based on Linux. So all of the servers are going to be running Linux. You are going to be working with containers. Packaging software in a modern fashion involves containers. Containers are Linux. You're going to be working with cloud providers that run on Linux.
-
Automation. So Linux is built for automation and shell scripting that we're going to look at. But CI/CD pipelines are nothing but glorified script runners. You are running a series of scripts to test your software, to build your software, and to deploy deploy your software. All of that is just done through Linux. All of these tooling is based on Linux. So it's extremely important that you start your DevOps journey if you become to become a DevOps engineer to get a firm grasp of Linux and especially the Linux command line. And that is what we're here for. So finally, we have talked about Linux, what the shell is. And now finally just one final term and that is the distribution. And that is what we um uh when we've done that, then we are done with this module and we can finally start running some commands again, but this is very important fundamental theory that you need to understand.
-
So finally, Linux is just the kernel, but a distribution packages the kernel with additional software in order to make it a complete operating system. So you can actually the Linux kernel, you can you can actually see the kernel archive and you can actually download the kernel. You can go here and download the the kernel, which is 150 5 megabytes. But you cannot just download this and run it. Like this it doesn't work that way. For the kernel to run, it needs a lot more. It needs the, for example, a shell. It needs to have all of these utilities like LS and and all of these things. Those those are not in the kernel. All of that is separate from the kernel. So in order to make a a operating system that is usable, you need something that's called a distribution.
-
And that is what Ubuntu does. So we've done Ubuntu Server. So this takes the Linux kernel and adds all of the the packages around it and and and and configures it so that you can actually install it and have an SSH server. So there are many different distributions. We are going for Ubuntu because it's beginner friendly and it's used in a stunning amount of enterprises. Debian is what Ubuntu is based on. It's a more minimal but also more stable version of Debian even though Ubuntu is extremely stable anyway. We have Red Hat, Rocky Linux and Alma Linux. So Red Hat is basically enterprise Linux. [snorts] So big companies they um they want Linux that is very stable, right? And Red Hat is a company that takes the Linux kernel and then creates the Red Hat distribution out of it and then provides support with that. So for example, the Dutch National Police is running Red Hat and they have thousands of servers running Red Hat and then Red Hat is also providing support for this. So that when there's a problem with the Linux with the Linux servers, then the police can knock at the door of Red Hat and say, hey, there's something wrong here.
-
We need your support and then they will provide that and they make sure that Red Hat is optimized for enterprise usage that also always works. For and then Fedora is basically the the user version of that. So here you see Fedora is sponsored by Red Hat. So Fedora takes um it's based on the Red Hat operating system and then you can take Fedora Workstation and then you have a Linux desktop OS. So what I'm running here is actually Fedora uh if you want to get know exactly Fedora Sway Atomic. This is what I'm currently running and this is um the immutable OS, which is a bit of a different rabbit hole. But Linux is also a graphical operating system. So I am I am we are we are focusing on the Linux command line in this course.
-
But all everything you see here is running on Linux. So I'm recording this video and doing everything on Linux. So Linux is also a graphical user interface distribution. It's not just the command line. Then there's Arch Linux. If you've seen any of my videos, you will know that I generally use Arch. I'm just running Fedora here as an experiment. But then there's Alpine. Alpine is one that you're also going to be finding in containers a lot because it's extremely minimal. So that is what a Linux distribution is. It takes the kernel and makes sure that you can actually run stuff on it. So this has been a long module with a lot of theory, but it's very important that you internalize this. So if you need to take watch it again, take some notes, and then review the commands that we have learned in this module. And now that we have a solid foundation, a solid understanding of what's going on when we actually do this SSH command and connect to our server, now now we can actually start working on our server with a good foundation of knowledge.
-
So in the next module, we're going to be going back to the command line and run some more commands. Okay, let's learn how to install software on our new Linux system. And this is done through package management. So there are a few questions we're going to be answering. How do I install software on Linux? What is a package? How do I update it? And so forth. So let's dive in. So before we can install anything, we have to understand what a package is. And a package is a bundle containing the software itself, so the compiled programs, the compiled binaries. It contains the configuration files, the documentation, and the information about dependencies or other packages it needs. So when you install, for example, a graphical application like a browser, it it actually needs a few things to be available on your system, and that is what's called a dependency. So for a browser to work, there needs to be a display server, for example, that kind of thing.
-
So a package will contain dependencies or information about them. And when you install, for example, a browser on a system that only has a command line, it's also going to suggest that you install all of the other stuff that is required to run that. Now a package is the software. It is the the the program and everything it needs to run. A package manager is software that is able to download those packages from what's called repositories, to install them, and then also to track them and to update them when they get outdated. Now every Linux distribution has different package managers. So Ubuntu and Debian, they have APT, the advanced package tool. Fedora and Red Hat uses DNF or RPM, depending on what you're using. On Arch Linux, it's called Pacman, and Alpine uses APK. So one one thing to note here is that these days that you have so many different distributions like Fedora, like Arch, like SuSE, so many different ones, but actually what they don't differ as much anymore.
-
The actual differentiator between those is usually the package manager. So when you learn a distro, you're also learning a package manager. That's basically what it comes down to. Now, a repository is a server that stores these packages. And we're going to be running apt install, so we'll get back to that. But these when you install a package, it needs to come from somewhere. And this is also why why we activated bridge networking in our virtual machine, if you're running a virtual machine, because we need a connection to the internet, because these package servers are connect you can connect to them over the internet, download the software or the updates to your software and then install it on your system. Now, package repositories, there are many different of them out there. So a distribution also comes with its package repository.
-
So um there's a package manager, but connected to that is also the default repository. And for Ubuntu have their own, Fedora have their own, and Arch have their own repositories. So these repositories are also being managed and maintained. So in the case of Ubuntu, it's Canonical that is maintaining those packages. In this case, it's Fedora that is maintaining those package repositories. And made a mistake there. They're not maintaining the packages. They're maintaining the the package repositories. Because these package repositories very often contain open source software. And therefore, when new updates are released, these updates first need to be tested and vetted to make sure that there's no viruses in there, right? And that is where, for example, the Arch User Repository, Arch AUR is a bit controversial and also a um security risk in that sense. So if you're using Arch Linux and you're using the AUR, this repository has no vetting. So AUR packages are user produced content.
-
They are completely unofficial and have not been thoroughly vetted. Any use of the provided files is at your own risk. So the AUR in fact has malware in it. So it has packages that will install stuff on your system that you don't want, that can hurt your system. So in other words, you have to be careful which repositories you use. Now if you just we we are using Ubuntu server and that means that we're using the the repository of Canonical. Let me see. Repositories Ubuntu. So what are repositories? There are literally thousands of Ubuntu programs and then there are different repositories. So you can read about this um about this here, but what it comes down to is that when you're using Arch Linux, you can use the AUR, which is not vetted, but Canonical is vetting this software.
-
So when you are installing software from the official Ubuntu repository, you can be sure that this is safe software. That these these packages have been vetted so that there's no malware in them because Ubuntu is something that is used on enterprise servers. So you don't want to have a virus being spread to millions and millions of servers, right? So that's why this software is carefully vetted and tested. But this also means that the software is also not the latest updates of everything. So the the appeal for using something like Arch Linux is that you can always get the latest versions of everything. So the latest features all are always available to you, but that also comes with a risk. Ubuntu and Fedora, those distributions are a bit slower and you don't get all of the latest versions, but to be honest, in this of your journey and where you are now, when you're learning Linux, you don't have to worry about any of that. But it is important point to make that you have to be careful which repository you do you use, but when you're using the the main repository that comes with your Ubuntu server install, you cannot go wrong.
-
So let's then try to update our system. So I'm I'm logged in and I'm going [clears throat] to be running the command that I saw there, apt update. So when I when I run this, it's going to say permission denied. I am not able to update my system. So why is that? Because updating the system requires [clears throat] administrator privileges. So if you've ever you are you have been running Windows probably and when you sometimes install things, then it will require you to to say run as administrator. Right? Or also on macOS, you sometimes have to run things as administrator. Well, that is the same concept here. You need to be an administrator to update the system. And currently this user is running as a user, but not as an administrator.
-
So for this, we have the sudo command. And sudo stands for super user do. So sudo apt update. Then it's going to prompt me for my password in this case. I'm doing that and now the update command will work. So now it's fetching the latest updates from the repository. So what is sudo? So super user do. It runs a command with administrator root or root privileges. So in Linux, there is the convention that the the the super user the the the administrator user is called root. The another word for another place where you will find root is the root file system. So earlier we were doing LS slash, right? Well, this is the root file system and you have to envision this as a tree and we're going to learn about the tree command later, but if you have a tree of things then everything starts at the root, right? And in this case all of all of the different things need to start somewhere.
-
So we have this and this and this is very ugly, but you get the idea. Everything needs to start from the root. So there's the root file system. So there needs to be a place where everything begins and that is this LS slash. Slash stands for the root and then there is the root user. So regular users can't modify system files or install software. You need elevated permissions. You need to become root. And think of it like Windows. Do you want to allow this app to make changes um or you need to run as administrator? Now the root is actually a user on your system and we're going to be learning about users in a following module, but there is a possibility to change to the root user, but this is bad practice. So anytime you want to do things as a super user, you run the command sudo and that's why we ran uh sudo apt update. Now do you see what I did there? I was on the command line and I can tick back through my history here.
-
And you remember the history command? This shows the history. Now if I press up arrow I can actually go back and forward to the history. So that's how I got the sudo apt update command there. So we have to be permission we have to get root permissions because we want to, because we need to update our system. This requires administrator privileges. And that's what it means, sudo. So we ran sudo apt update. So what did this do? It did not update our system actually. It did not Nothing has been installed yet. If we look at the actual output, it's saying get and then it's going to see see all of these URLs. So you have noble updates, noble backports, noble security. This refers to all of these repositories that are configured on our system out of the box. And this this is because we downloaded a distribution and that means that we have some repositories configured out of the box.
-
Now this downloads the latest list of all available packages from the repositories. It doesn't install anything. It just updates the list of what's available. So before you upgrade your system, so there's two different words. There's update and upgrade. And before you can upgrade your system, you first have to pull in the list of the latest packages. And that is what the update command does. Now let's run the upgrade command, which is going to actually install those packages. So sudo apt upgrade. And this is now going to show a list of all of the things that are outdated. So the following upgrades are available to me. And this all looks like gibberish to you. And that is completely fine. What we need to remember here is that this is actually showing which packages are being upgraded. And [snorts] since we are using Ubuntu Server with the default repositories, it is safe to just accept this. When you're running Arch Linux, then you need to actually be very careful with reading this because you need to know exactly what's going on.
-
That's why you I don't recommend using Arch Linux as a beginner. So now you see that this command is now going to pull in all of these new upgraded packages. It's going to um then process them and install them for us. So while this is going, let's uh keep going. So I you saw there that I typed enter or yes to confirm. It's asking me, hey, are do you are you sure that you want to do this? And I said yes, I want to install these and that's what it's doing now. Okay, so we're almost finished. The Raspberry Pi is of course a very small computer and it's not the fastest computer in the world, so it takes a little bit of time. But now we are almost finished processing this and you see that it has produced a ton of output and it's all just unpacking things. It's then putting them in the right place and installing them as you see. And here we go. Our system is now completely updated.
-
So this was this is just by up there by running one command, you can update your entire system and update it. So we've learned that. Next, let's see how we can um search for packages. So there there is no like GUI for this. Like there there are of course graphical applications, but when you're running on a server, you need to learn how to search for packages from the command line right? And to do that, you run the command apt search. And we're going to be searching for the package apt search htop. Now notice that I was not I did not need to be root for this. I did not need administrator privileges to do this command. So the command itself can be run by users, not root users. It's just that similar some operations of the command, for example, updating and upgrading, that needs to be done by an administrator. But anyone can search the package repositories, right?
-
Now htop is a package is a process viewer, so you say interactive process viewer. So that is one that you will find often on servers, etc. So let's install that one. sudo apt install htop. So that is the the syntax for installing. We need to be an administrator here. We're going to run apt and then the install command and then the name of the package. Now it's going to install it. Actually, it was already installed on my system, so maybe this was not the best example, but you get what I mean. You can search for a package and then you do apt install htop and later we will be installing it. Now now that we have installed it, we can run the package and this is what it does. So if I make this a little bit bigger, then this is basically what you could call a task manager or equivalent of task manager that you have seen that you will see on Windows systems. Here you see the CPUs, the the the processes and the CPU they're using.
-
You can sort on memory by pressing capital M. You can sort by CPU by pressing capital P. It shows how much memory we are currently using and in our case we are using 205 and 5 megabytes of our available four. And that is what htop does. It shows us our processes and we can interact with them. Now let's say that I so this this package then came with my system, but let's say I want to remove the pack the the the package. I don't want to have htop installed on my system anymore. Well, what I can do is sudo apt remove htop and this is then going to look it up. It's going to say do you are you sure you want to remove this? Yes. And this is then going to remove htop. And if you want to remove everything including config files, you do the purge command. apt purge htop. Now everything is purged and everything is removed. And if we then want to install it again, then we just simply run let's do the let's just do that. sudo apt install htop.
-
We can install it again and when I run htop, it runs again. So that's how easy it is. If we want to show all of the list the installed packages that we have, then we can run the command apt list installed htop. And that actually let me open a window that is a little bit bigger so I can switch to them. So I'm going to open a new window. And all of this what you see me doing now from the keyboard, you're going to be learning this in a later module. So if I run htop here, then this is a little bit bigger and then we see that it's still available to run if I run the apt search no apt apt list installed. Now we get the full list of everything that is installed in our system. It's a lot of packages. So what do we do if we want to filter something that? And this is going to be the first time you see the grep command. We're going to learn a lot more about grep later, but fundamentally what this does is that apt grep filters text output and we're going to be learning about Linux Unix filters later.
-
But for now, we are just simply taking the out the the output of this command and filtering it with grep. And this is going to be explained in detail what we just did did. But this is basically how you can work with the list installed. We have already done the updates, right? So let's then install a few tools that we're going to be using. For example, htop, tree, curl and vim. A lot of them are going to be installed already. So we are we're just saying we want all of these, but in this case the tree command was not installed. So it's it it apt then looks at the stuff that we have installed already. It's going to determine which one do we need to install then it's going to say do you are you sure you want to install tree? Well, in this case, yes, let's install tree. Those are a few packages that we need to have. So, let's run tree version. And then we see tree is now in this version. Vim version.
-
We see that there are several vim vims installed here. That's okay. Um vim htop version. We see the version of those. So, we are we are able to run them. Htop we've already tried. Now, let's do the tree command. That's a fun one. So, I'm going to switch to my bigger window. And if we do tree at c apt, what do we see? Wow, cool. We see a full directory tree here. If I do tree Let's try something fun. Tree root. Ooh, now we see a lot of stuff happening. It's actually creating a tree of the entire root file system that we have on our system. So, this is a bit too much to uh to look at probably. So, let's just stick with the tree at c apt. So, what this does is if we do an ls of at c apt, then we see that this has several directories here.
-
And here you see those apt conf d, keyrings, sources list, etc. All of these are listed here uh as well. But then it's also going to show what is in those directories. So, this is going to give you a nice overview of what's running. So, tree is a very useful command. So, to wrap up, these are the commands that we have used in this um in this module. Now, the challenge for you is to find and install a package called neofetch, run it, and then remove it. And then the solution of this exercise is below here. Welcome to module four where we're going to be learning some very crucial command line skills, namely navigating the file system, how to move around, and also how to create files, how to create folders or directories, copying and moving files, and also how to get help when we don't understand what something when what a command does.
-
So there's a lot to cover, so let's dive in. The first thing you need to understand in Linux is that everything is a file. Everything is represented as a file in a Linux file system. So regular files you on you are used to this from Windows etc. where your documents, scripts and programs are files, but in Linux directories are also represented as files. It's a bit of a mind-blown moment, but that's how it works. Your devices are also represented as files. So your hard drive, if I this is the lsblk command, you don't have to actually remember this right now, but the this command shows you the devices, the hardware devices that are on your drive now. So if I do ls dev and then here if I do mmc, then you see that this mmcblk0 is here as a file, right? So if I do ls dev, then you see there's tons of things here that are actually devices.
-
These are all devices on your system. And we have our loopback device, we have our u random, we have ttys, so your your terminal interfaces etc. So these are devices represented as files. Your network process your network sockets and processes are also represented as files. And we're going to be looking into that when we learn about processes as well. So the root directory, the top of the file system, I already explained this, is called root. So not to be confused with the root user, but if we LS root, LS root, then we see again we see that everything springs from here. All of the like the root of a tree, you have the root and then all of the rest comes from root from the root. And everything branches from here. So there's no drive letters like C or D or anything like that.
-
It's just one big tree that starts at root and then branches out. So maybe there's a good Linux root file system. Maybe there's a nice image here that will show it. Uh Yeah, okay. There are a few. This one this one represents it pretty well. So this is the root where everything is and from there all of the rest springs, right? All of the rest comes from root. So everything starts here and then from there you have all of these other directories like your home directory temp etc. So everything springs from the root. It begins there and then uh we go from there. Um so in in root we see all sorts of different things. We we see thing slash home slash temp slash boot, blah blah blah. So these are all um all required and necessary to know at some point, but right now what you need to these are the ones that you need to understand. So slash home is the user home directories. So your files live here. So if we do PWD, we see that home user. So my username is user.
-
You may have chosen your own name and you see that we go on the root file system. On the root file system there is a root a directory called home. That's the one you see here. And we can actually just LS home. And And see that the home directory contains only one, in this case, user. And when we add more users, we're going to see that we are adding more home directories. So, this is how it works. So, your every path on Linux starts with the root and then takes one of these directories and then branches out from there. The at C is system configuration files. So, we already listed that one out. LS at C, you will see it has dot conf, right? And all sorts of things here. These are all configuration files for our system. Slash var is variable data. So, if you do LS slash var, then here you can find logs, cache, things that are variable. So, things that change a lot, like databases or mail.
-
Slash temp is temporary files. And this is an interesting directory because the temp directory is cleared every time you reboot. So, all the time when you're like just trying things out or or you're downloading files that you're not going to be needing anymore, a good habit to teach yourself is to put that stuff in temp and then you know that it's going to be automatically deleted. Slash user contains user programs and data. Bin is essential command binaries. Sbin is system administration binaries. So, let's do LS slash bin. Here we see all sorts of different binaries. These are all commands that we can run on our on our programs. So, so here we see, for example IP. So, if we do IP, this is now running the binary that is located in in slash bin.
-
We also have LS slash Sbin. So, these are all system administration binaries. So, these are all commands that you can run on your system. So, opt contains optional third-party software. So, let's check out if we have any of that. No, we have nothing installed on our Ubuntu server yet um in terms of that. So that's good. /dev is the device files. We've already seen that. And then there's proc process and kernel information. And this is an interesting one. ls proc this actually has uh like we're going to be getting into processes later, but if you run htop, we've already seen that. And you see on the left column this has PID here. The PID and here there's PID 1 or PID 780 0 etc. Well, let's remember this word 780 0.
-
Here if we ls that, then we see that there is a pro a file here or directory rather called 780. So we can actually go and check out if we ls proc 780 here. We see that we are listing it now, but we are um not allowed to do that, right? Because we have permission denied. So what we can do is we do sudo ls proc 780 and then we have to enter our password. And now I can see the contents of this directory 780. So it's very interesting concept that the processes that are running on your system are actually represented as directories and files that you can also check out and look at and do sorts of things with all sorts of things with. So we're going to be getting that into that later.
-
So we have been exploring quite a bit. We have already done ls at C. Now let's check out ls var log. So ls var log. This is going to contain all sorts of logs from our system which we're going to get back to. And let's just now talk about absolute versus relative paths. So the absolute path starts from root. So you always, this will always work regardless of where you are. So home, user, documents file, because it starts with root, it will always work because this is the the full path, you could say. The full path of your um of your file. This is the the full path of it from root to the file. Now relative file path starts from your current location. So if you are in home username, then this is the path towards file txt that happens from your local path. So then there are a few shortcuts here. So there's the current directory and then there's the parent directory and then there's the home directory. Now we're going to be learning about this in the next section.
-
So I said let's do some essential navigation. First of all, where am I? PWD, I'm in home user. Print working directory. Now if we change the directory, how do we do that? We use the command CD, change directory. Let's go into var log. And now we are in var log. So let's verify. We see it in the prompt. But when we run PWD, we now see that we are in var log. So if we want to go back to our home directory, we have to type CD tilde like this. CD tilde and if I know the PWD, we are back in home user again. Now one interesting thing is that if you just write CD, you will just go back to um your home directory as well. So let's go back to var log.
-
I'm now in var log and P if I clear this PWD, I am in var log. If I just type CD PWD, I am now in home user again. So, CD always takes you back home and there's no place like home, right? Now there is this now that there is the the these dots that we were looking at earlier. So, these might be a bit confusing, but it will make sense later. So, the the dot the the period refers to the current directory and dot dot refers to the parent directory, so one level up. So, if I go back to var log if I now do CD dot dot I am now in var. So, I'm going back one step in this tree you see here. So, you go back to the parent directory. If I go to log then I can LS here. I see directories, but the parent directory of log is var.
-
And if I want to go there, I can do CD dot dot. And this is very very useful to navigate around like this. So, let's go back to the home directory. I'm now in my home directory, but with PWD and CD this is all you need to navigate around. PWD being showing your location. Next there's also the previous directory. So, let's go to var log again here. And if I now do CD dot dot I am in var, but let's say I want to go back to log. Well, I could do CD log like this. I'm now back. But if I go back to var CD I'm now in var again. PWD var. If I want to go back to log, I can also do CD dash and now I'm in log again. Now this is useful if I for example go to CD and then Etsy and let's see what what do we have in Etsy system D like this.
-
So, CD Etsy system D. This This very different place, right? It's very different from var log. So if I'm now here, but I think, ah, I want to go back to var log again, I can do CD - and boom, I'm back in var log. So CD - always takes you back to the previous location you were in. Now let's go and do some more um um advanced listing. So we are in uh let's do let's do it in var log. And I'm going to make this a little bit bigger so that we can see it better. If I now do LS, we see just a number of uh things in this directory. But like I have some colors here, but it's not completely clear to me what which one of these is a directory and which one is a file, right? So let's do LS L. And now we see a very different output.
-
We see a few interesting things here. So first we see that it has several columns. And this this you're you're going to be living with this kind of um the this output is going to be extremely extremely important and LS is going to be one of the most typed commands you do. So it's important to to learn it properly. So when we see this in the first character of the the the column here, this shows you what it is. So a dash is a regular file. A D will be a directory and then there's another type called a symbolic link, but that's a little bit out of the scope of this course right now. So what we see here, and we can see it in the colors as well because I have some highlighting going on that there are a few directories, but also a few files. And all of the rest of these columns we're going to get into when we're going to learn about permissions.
-
Let's do LS A. Here we see the a different we see a different output. We see now we see all the files. So this includes hidden files and one that is better to show if I now go to my home directory and if I do ls I see nothing, but if I do ls a whoa, now we suddenly see that there is a bunch of stuff here. So ls just shows the the the normal files, but ls a shows me the hidden files. And if I now do ls la we see the full output of this. So ls la shows all of the files and directories including the ones that are hidden. So we see for example that there is a ls dot config. I can actually see the the the the contents of that directory. I can still interact with it, but we don't see it in the standard output of ls.
-
So ls la is going to be one of the commands that you're going to be running the most. You can also do ls lh. So here we um do a human readable format. That's the h flag there. So ls lah that is if you see if we do ls la we see here that it has some numbers here and if I do ls lah we now see that this now transformed to 4k and 3.7k. In other words, it's converting those numbers to human readable format and you're going to be seeing this in other commands as well. So this is one of the most useful ones ls lah. And now let's go back to the tree command which we have already learned about. So tree this one is going to show nothing because we have hidden files, right? So let's maybe go to var log again.
-
And if we run three here, now we see a lot more. So if I go to three L two, this is going to limit it to two levels deep. So if I if we again do um LS or a tree root, then we get so much, right? So much output. But if we do three L two root, then we only get the level two directories. So we're only going two layers deep. It's still a lot, but it's less than what we were seeing before. So you can limit it to the levels that you want to see. Now let's go and uh work with directories and create them etc. So I'm going to go back to my home directory by typing CD, clear that up, and I am now in my home user directory. Let's create a directory. And the command for creating directories in Linux is make dir.
-
So let's create a projects directory. Make dir projects. And if I now do LS, now we see that I have a projects directory in my home directory. If I do make dir P and then projects and then we're going to create work 2025. [snorts] Let's update that actually. Okay. So then if I do three now, then we see that we have projects work 2025. So the P flag to this command creates the parent directories. P for parent. So it it if I do um if I do make dir and then test hello world, then it will say I cannot create it because there the test directory does not create that. Uh this does not exist yet. But if I do make dir if do it like this, and I add dash p here, then it will work. If an out of tree, then we see that we have projects work 25 and test hello world.
-
we've already um done the touch command. So in my home directory, I will do touch notes. And if I now LS, then we see that we have a notes txt file. But we can also copy the file. And that is what we do with the CP command. CP notes txt notes backup txt. And now I have a copy of that file. Even though it is empty, we have the copy of it. Now we can also do copying to a directory. So again, I have my notes dot txt. And if I run CP notes txt to projects, then if I do LS projects, we now see that I have my notes txt there. So again, let's do a tree. So what I see now is that I have my my current directory. And notice that it has a dot, right? We saw that it's dot current directory. Dot dot is the parent directory. So dot contains notes backup and notes txt. It contains a directory called projects.
-
And we copied that notes txt into the projects directory. If I want to copy a directory with its contents, we have to use the R flag here. So if I have the note the projects directory, if I then want to make a copy of that, I do CPR projects. And then I copy that to projects backup. And now I have a projects backup directory. And as you see, it has also copied the notes txt that was in there and the work 2025 subdirectories. Now let's learn about moving and renaming files, which is also very important. I'm going to be moving it into a documents directory. Well, first of all, we need to create a directory. So try yourself. Create the documents directory now. How do we do that?
-
We do make dir documents. And if I then want to move notes txt to documents like this, and if I now do LS, we see that the notes txt is gone. And if I LS documents, I see that my notes txt is there now. If I do the move I flag, it will prompt you before overwriting. So let's try that. So um if I touch a new notes dot txt, if I now move this with I to documents, move I notes txt to documents, then it's going to ask me, hey, do you want to overwrite this? Because I actually saw that your documents directory contains a notes txt here.
-
But look at what happens when I remove the I flag here. If I just remove this, it just does it. It just overwrites it without asking me for permission. So the move command is also a very you have to be careful with it because you can do a lot of damage by moving something that accidentally has the same name. So you have to be very careful with that. The best practice is to actually have the I flag with it. Now let's learn about no deleting files because we have a lot of stuff going on here, right? So let's remove notes backup dot txt. That is now removed. It's delete and remember it does not confirm, it does not ask you for um anything. So then we can do um the the next command to remove directories. So the one that we we create is test directory. Let's see RM R test.
-
This now has deleted all of the the directories and and the contents of it. And again, it is not prompting us to ask it's not asking us are you sure about this? So you have to be very careful with what you're deleting. So let's then the remove let's clean everything up. We're going to remove the projects backup directory. We're going to remove the projects directory and let's also remove and also let's see documents LS documents that contain something now. If I do RM documents that is going to be um failing because it's saying hey this is a directory. So you have to pass the R flag if you want to recursively. So if you want to delete everything that's in that directory. So let's do RM R documents and now it will allow me to delete it.
-
Then there is the an a a safe way to delete directories. So if I do make dir test again an LS I have one directory here just the test directory. And if I then uh touch test slash hello then if I now do a tree then we see that we have a directory with the hello file in it. If I now do a RM dir which is the directory for deleting directories. If I RM dir test now you see it's failed to remove because the directory is not empty. So RM dir is a good practice to teach yourself to when you're deleting directory directories do not use rmr test rather use rmdir because this case you won't be able to delete stuff that's in the directory. So you oh yeah there's actually something in there. Let's see oh yeah there's this hello file in there. So the best practice is to just remove the test hello file first and if I now run rmdir test now I'm able to delete it and now our home directory is completely um clean again in except for our hidden files of course.
-
So ls now everything is clean again. So now we've learned how to um how to create files. Let's now learn how to find files. So first there is the find command and this is a very important command to to master to learn a lot about because it's so extremely useful in Linux specifically that I'm going to say it multiple times it's very important that you learn this command well. Oh actually I skipped over this one. You will see in Linux memes etc you will see this one which is called rm rf slash. So if you you know by now that this is going to then to delete the root file system and F actually means force. So never ever run this. This you should have to be very careful with rm rf in general but you should of course like you can realize now that deleting your root file system is going to lead to problems. So never ever run this and make sure that you understand what's going on with that command.
-
Now let's find some files by name. So first of all in order to for this to work I'm let's go to our home directory and let's touch hello.txt and touch world.txt. Now LS this, now we see that we have two files called hello and world.txt. If I now run this command find home name.txt, what this is going to do is it's going to find all of the files that have a .txt extension in home. If I now add a file here called touch config, I see that I have config. If I run that find command again, we see it's not finding the config file, right? But if I do find dot name config, now it is finding it.
-
And notice the difference here. So here we are actually saying find in /home, find all of the files that have txt and the star is a wildcard. So find files with a name that have a wildcard and .txt. So everything before and txt. This if I run the same command find home and then name config, now it's only going to find home user config and not all those text files, obviously because that is the filter that we're doing. So let's say we want to find all the configuration files in etc. What we can do find etc. and then name conf. And this is going to print all of the conf files that are located in the etc. directory. This is an extremely useful command to learn.
-
You can also find by type. So if we do here, if we do find var, so in the var directory, let's find anything that has the type D, so the type directory with the name log. And here it is actually showing us a few permission errors because we have no permission to go into these var lib directories, but we see here that it has var log. So if I run this as sudo, so sudo and then sudo find var type D name log. Now it's just outputting the var log. See? This is how you can filter on type directories because in var log, you see if we LS var LS LA var, we learn that we can see the oops, LS LA var. We can see that var contains a few different directories, but in this command we are filtering the directory names with log. In this case, it is only one directory here.
-
So these are a few useful find commands. You can also filter by size. So this one, find var log size, it's going to show everything that is bigger than 10 megabytes and it's saying oh, permission denied. So now I'm going to teach you a little trick. If you do sudo and then bang bang, exclamation mark exclamation mark, then it's going to run the the same command as root. So I do find permission denied, sudo bang bang, and then it's going to show me the then I'm running the same command as root like this, but there are currently no files in here that are bigger than 10 megabytes. So it's not not outputting anything. I can actually do the same one with directory.
-
If we find type D name log, we're getting permission errors, but if I do sudo bang bang, then it's going to see we are running sudo find var, so it's running the same command as sudo and then it's outputting var log. So that's a nice little trick there. Another way of finding things is called locate. So locate is faster but less current. So locate uses a database of your the of your of your file system. So let's see if we do locate find, we actually see that it's actually not installed. So it may not be installed by default. Let's just install it first. So sudo apt install p locate. It's not always available as you see. If I now do locate find, then we see that it is going to um give us all sorts of um paths that contain find. So user bin find, find mount, pam find, find utils, everything that contain has has the word find in it, it is now showing us, right?
-
So that's also an interesting command here. Um let's create a file called touch misha.txt. If I now do locate misha.txt, it's not going to be able to find it, but if we do sudo update DB, it's now going to update the database of the file system. And if I now do locate misha.txt, it is able to locate it. So locate is faster because it has a database of everything that's on your system, but you need to update it for in order for it to work. So now we're going to learn about how to find the location of commands. And for that we use a different command called which. So which LS outputs the path of the the the command that we're running. So our command is living somewhere on our file system. And we already saw that LS bin contains a lot of things, right? So here there's for example Nano. So if we do which Nano, we now see user bin Nano.
-
And actually that reminds me in the previous module we installed Neofetch, but I never showed you. So let's run Neofetch actually. [music] And what this does, it shows you information about your current system. So we I'm running as user at Kato and our uptime is 3 hours. We have our CPU and so much memory available to us and we are running Ubuntu. So that is what Neofetch does. You will see this a lot in Linux memes etc. So which outputs the the location of a command. But there's actually a better way of doing it and that is command V. Command V make dir. Command V is a good one to teach yourself. It's a little bit more to type, but command V is more portable. It's it's available on more systems and it's going to come in handy in shell scripts specifically because this returns the correct return code and which does not. And we will learn about that in the next course.
-
But command V is actually the correct one to use. So if we do command command V make dir, then we see it's located in user bin make dir. And this is useful because when you have your own commands or you want you're wondering where something is installed, you need to know how to get the path of it, right? Now, what about CD? Let's try command V CD. Huh? This is weird. It's only outputting a only the word CD. Well, where are we? We are in our home directory. And if I LA here, we see that there's no CD here. There's no way that we can that is run here. So why is that? Well, that is because CD is a shell built in. And we're going to and that and that is a little bit different than a command. So shell built in is something that is included in your bash shell. So it's not a separate command. It's not a separate binary on your system, but it's built into bash.
-
And you can figure out what what if something is a built in by using the type command. So type make dir. We see make dir is hashed. So it's a binary located here at user bin make dir. But if I do type CD, we see CD is a shell built in. So type tells you if it's a built in or a or a command or a a separate command. And uh this is important to know because you know for example, you might be looking for the the location of CD and you can't find it. And that's because CD is a shell built in and it's it's baked into your shell. So bash contains CD rather than being it is it being a separate command located in user bin make dir for example. So we've learned a lot of commands in this lesson, but how can you keep learning on your own, right? And one of the most important commands that you're going to learn is the man command.
-
So let's I'm going to do this in a bigger window. So if I do man LS, then we we get the manual page for LS. And man pages are some of the most useful resources of Linux because the great thing is you can literally get help about anything right from the command line. So anything that we have been doing man make dir or man which all of these if you run this it shows you the documentation of that command. So if we go back to man LS this is just one page but look look if I press the down arrow it has so much information. It tells you exactly what you can do. LSI, LSK, LSL, we've seen that. Use a long listing format. There's so much that we can see here.
-
And it tells it gives us examples. It gives us information who created it, when it was created. This was actually written by by Richard Stallman. So the the LS man LS shows you all the information you need about the command. If I want to exit this I press Q. And this is extremely extremely important skill to learn to navigate man pages and I'm going to give you some advice that was given to me by mentors that I respect a lot. But when you're learning Linux and specifically learning the Linux command line there might be an instinct that oh I'm I'm I I have just used the make dir command. Let's look it up make dir and then you can search it and you're going to search the internet and read about it.
-
Rather than doing internet searches try the try to make it a habit to start reading the man pages instead. Because [snorts] if you get good at at doing this, so man make dir, if you get good at navigating this, because Linux has so many commands, so many flags to remember, it's a key skill to be able to access the information you need right from the command line. So if so if for example you're thinking to yourself, how do I list the hidden files again with the tree command? So if then it might be like tree hidden files, that might be your first instinct to start googling this. But you can also if you're if you're good, you will learn to just do man tree and now you see the tree. And if I then search hidden, then we see oh yeah, all files are printed. By default tree does not print hidden files, but in no in when you add the a flag, it's going to also print out the hidden files.
-
So let's test it out. I'm in my uh my home directory. If I do tree, I only see config hello, but if I do tree a, I see all of my hidden files as well. And I access that information right from the command line like this. And now we're getting into why you should get good at the command line. Like the command line interface is so fast that it you're only limited to the speed of your typing. But when you see me moving around like this, like I can open this up, I can split a window, I can cat my etc uh OS OS release like this. And if I then here go and I want to man make dir, I can go around and how did I do it again? Oh uh make dir p. Oh yeah, if I then go back and make dir p p hello world etc. So I I can have all the information available to me here. I can edit text files, I can look up information and you can really get if you get really good at this, RM uh dir RM r hello world.
-
If you get good at this, you you you don't you never need to leave the command line. You can interact with your system completely on the command line, and that is why it's so important to focus on this as an DevOps engineer, because almost everything has a command line interface that you're going to be working with. So I work almost exclusively from the command line when I'm doing productive work. And being able to read man pages and getting the information that you need quickly is a very essential skill of that. So we have covered opening the man page. Let's just do man ls again. Let's I I'm now like typing down arrow or up arrow. There's also the space key, so then you like page up and down. Let's say we want to find information. If we go down a bit, inode here, right?
-
So let's say I know that there is something about inodes in this command, but I'm at the top and it doesn't say it. So how do I search for that? Well, that is the forward slash like the root. So if I do slash and then inode enter, it's now going to directly go to inode and highlight it, right? So if I'm if I'm working on my system, it's like, how do I list inodes again? Man ls / inode and boom, the information is there. No browser needed, no searching. Man ls inode boom. Oh yeah, okay, literal. Oh yeah, there it is. How do I do all Oh, all okay, easy. I can easily do this from the command line and super easy to find. So the slash pattern is extremely powerful. Space to scroll the page, b to the previous page and quit to quit it.
-
So man cp I forgot just read it space space space b b b b to go back up. And we have something about preserve here so slash pres and then we see all preserve. So this is so important to learn this. So practice with this. Man pages are documented in sections. So sometimes a name exists in multiple sections. So for example password is both a command and a file format. So if we do man password then we get the the the main password and we see here password one. So one being user commands. But if we do man five password we get something different. Password five file formats and configuration password the password file. So there are two different um locations for man to be in and these sections then correspond to what we just saw.
-
So section one is the user commands what you run in terminal. Section two system calls three four and five being file formats and config files. So if you want to get the the file page of man you have to do man five password. Now if you don't know the exact command name we can search with man k man k password like that. Then we see that man the password actually has quite a few different locations. There's the one the change user password that's the one that we do see when we do man password. We get password one right? For example if we want to open update password so man eight update password and then we get the update password eight. See? So that's how that works. And man k is really useful so man k cd then we get all of the everything that's look about cd so there should be a uh Interesting. Is is man CD? Oh, man Well, this is This is a good example.
-
CD does not have an manual entry. And we're going to get work I I will Because this is a built-in, remember? And we're going to get to that in the next section. But let's just um uh finish this. So, if I do man k make dir, then we see, okay, man only has one entry. So man But if I do man k system ctl, for example, then we see there are different a few different um uh results. So, man k for searching and then if we search, then we can open the correct one with man 5 password like that. Very useful commands that you need to master. And then finally, there's the help command. So, remember the CD. So, if we do uh man k CD, we saw there is no nothing for the CD command.
-
But if we Remember, if we do type CD, we see it's a shell built-in. And to get help for shell built-ins, you need to do help CD. And now we get um some help about this. So, this is a bit of a a strange quirk, but I recommend writing this down. So, if you're finding yourself uh I want to I I'm using the CD command, but I want to learn more about it. So, I do man CD. Oh, there's no manual entry for CD. So, what is CD then? Then Well, then you do type CD. And then it says it's a shell built-in. And then you know, oh, okay, it's a built-in. So, I have to use help CD. And then you get help. So, practice with this. Finally, there is the help flag. And this works with almost every command. So, if you do um ls help, then you get some help about this. So, this is not a full man page, but it does give you a lot of information. If you do which help, it shows you uh oh, which actually does not have this, so it doesn't always work. Make dir help shows you some um information about it.
-
So, almost all commands have the help uh flag, and you can actually see it in the help display this help and exit. And if we do man mkdir, and if we search for help, then you will see the help flag here documented as well. So, that is also one to do. So, when do you use which? Full built-in full documentation for command, you do man command. For a built-in, you do help. For a quick reminder of the options, you do command / / help - - help. And if you don't know the command name, do the man keyword. So, try these commands out for some practice. Here is the overview of this lesson and everything that we have used in this uh command. And now, here is a little challenge for you. So, create a project structure, add some files, and then clean it up.
-
Remind yourself of the the um the mkdir, cp, etc. So, create an empty file called readme, copy it over, rename it, and delete the entire uh course directory. And actually rename, I think we haven't actually covered that. So, let me just quickly do that. Going back to the home directory, we we have seen how we could move things. But if I want to rename something, so let's say we have misha txt, I actually have to do move misha txt to sammy txt. And if I now do ls, then we see that misha does not exist anymore, and now it is Sammy.txt. So, that's how you can rename files by using the move command. So, as you are doing this, um read the man pages for every command. So, try to figure out a little bit more about the command. So, LS, make dir, etc.
-
Do this little project, and then there will be the hint to help you solve the project. So, we've covered a lot in this one. I hope it wasn't too fast and too dense, but it is uh all very important stuff. So, if you have to do this twice, then uh feel free to just repeat the module again and take some notes. And um I'll see you in the next one. Welcome to module five of the course. Here we are going to be learning about viewing file contents, searching for text and understanding file information. So, the fundamental concept is that you can look inside files without opening an editor. This is very essential for reading configuration files and understanding what is on a system, especially if the only interface you have is the command line. So, what I mean by that is let's say you have a doc file on Windows, right? Your Microsoft Word file. In order to open and view that file, you would use the Microsoft Word program usually, or maybe there's an XLS file.
-
You would use Microsoft Excel to open that. And the macOS or Linux equivalents. So, you're opening that file with an editor. But you can see the contents of files without an editor, and that is what we're going to be learning. So, in this case, let's check out the the cat command. We've already um seen this, but we've not really used it much yet. So, let's display an entire file file cat with cat. So, in this case, the file is etc hostname. And the output, the content of that file is Cato because the whole the hostname of this device is Cato. Again, everything in Linux is a file. So if I run the hostname command, it's simply going to return the contents of that file. We um we have seen the OS release um command, right? Cat at c OS release. But we are simply displaying the contents of that file. We're printing that to the terminal.
-
So cat works great for small files. But what happens when we do that on large files? Ooh, and now we see a bunch of output. And if I scroll through this, then oh wow, this is way too much. Like this is not useful at all. What what what are we even going to do with this, right? So you see me scrolling through the terminal here, but that might not be possible for your terminal. And [clears throat] uh if before in these tele these terminal devices that you saw, you were not able to scroll. There there was just the there's the amount of characters you have on the screen, but that's it. There's nothing you can scroll back through. So how do we then uh how can we actually open a file and scroll through it? Well, we've seen that a little bit with man LS. Here we are opening a file and we're able to scroll with the up and down arrow right?
-
But if we cat if we do the cat var log syslog, if we cat this, then it's just spitting it out to the terminal and saying good luck with it. But there is a different way, and that is the less command. If you run less var log syslog, then we have a what is called a pager. So I can now with the up and down arrows, I can page through this file. And when you're opening man pages, you're actually opening the the actual help file, the text file in a pager. So now I can actually page through this by pressing space or b, just like we learned in the man pages, and I can search it. So if I search for UFW and if I then press n, I can find the next occurrence. But if I want to find the previous occurrence, I press shift n, so capital n.
-
And then I I can scroll back. So that is very useful for reading large files. And here are a few more commands that you can do inside of less. So then we can also use the head command. So head is very useful because head only shows the first 10 lines of something. So that is something that um if you just want to quickly get a sense of, hey, what's in that file, head, okay, then it just shows you the first lines. If you do head 20, it's going to show you the first 20 file lines. And if you do head minus one, then it's just going to show you just the first line. Now you have head and then the equivalent of that to show the last lines of a file is tail. So if you do tail, and that's a bit of a joke, head, tail, nice, right? So var log syslog, this is actually the last um the the the last 10 lines of our file.
-
And tail 50 is going to show the last 50 lines of our file. Now this is pretty cool. This is going to be watching files in real time. So if you do tail dash f, [snorts] now it's actually showing the files in real time. So if I have this log open and we see here 42 scope deactivated successfully. If I then open up something new and I SSH into my server, then we now see that se session started 43 scope session 43 of user user. So here we see that I that apparently my sessions have a number and I'm now session 43 and it's now opened. And if I were to exit this by typing the exit command, then it will see session 43 deactivated successfully. So now it's logging the the the output the the the the contents of that log file in real time by running the tail -f command.
-
So this [snorts] is um it the f stands for follow and the new lines appear as they're written to the file. So you're watching it live. This is essential for debugging. So when something goes wrong, you can tail f a file and then you can like see if you can reproduce the error and see if um um if the if it's doing the expected behavior. So very useful skill. And to stop following, you press control c, which is a um wherever you are, if you are running a process and you want to go out of it, exit out of it, then control c is the main thing to um the main key stroke to send to end the current process, the current activity. Control c. Now let's cover searching for file contents because if we, for example, do the cat var log sys log again, that is not useful because it contains so ton of information.
-
But what if we want to take that information and and search it? So we have the the we have used it with a pager. But let's say I want to just get all of the errors of this that are in var log syslog. So if I do grep error var log syslog, then the grep command is going to take the contents of the file and then filter out all of the lines that contain error. So error grep is an extremely useful command and grep is something that you're going to be using a ton in your career and as a Linux user or DevOps engineer. So again, grep error takes the contents of the file var log syslog and then filters out all the lines that contain the word error. If we want to take the etc password file, and we're going to be learning more about that when we learn about users, but if we do cat etc pass wd, then we see it has quite a few lines in here right?
-
But let's say I want just want to see the line that contains root, then I just do grep root etc password and then I only get the root line out of that file. Extremely useful. Now there is also case sensitivity. So if I do grep root with a capital letter, it's not going to show us anything, right? Because I am it is it is searching exactly for what I'm saying in the grep command. Grep root is returning something. Grep root with capital R is not showing something. But if I add the flag dash I to it, then it is going to return it. So how do how do we know this? Well again, we can do man grep and then we can search for dash I.
-
And here we see it's called ignore case. Ignore case distinction in patterns and input data here the top of my screen here. Grab grab is extremely, extremely useful. We can do the if we now go back to the var log syslog and if we then do the insensitive one, then we suddenly get a lot more. So earlier we were getting if I just do grep let's maybe do it in the bigger screen. If I do grep var grep error var log syslog then I'm getting well about five lines. But if I then do grep I error I'm getting a few more because we're seeing here log util pie error and main pie error. So there's more things coming up here. So grep I is also um very important one to know.
-
If you want to show the line numbers of this then if you do the grep n, it's going to show you the line number in the file where this line is located. So that's useful information. And the grep v command shows lines that do not match. So you are filtering out the the the noise there. So if I do grep v error then I'm seeing all of the lines that do not contain error. So if I wanted to see just the normal operations in my syslog and not show any errors, then you use grep v. So you are inverse searching. Anything that does not match this this um search phrase is is shown invert match. [snorts] You can also search recursively. So if you grep r password in etc then you get all of the it's going to go through all of the files in the etc directory and search for the word. So here in this at C directory you see all of these files that apparently have the word password in it.
-
So if I'm looking for something if I'm if I have this massive directory with tons of files but I want to let say I have a lot of notes in my in in a directory and actually I have that. So CD CK this is my Zettelkasten and this contains about 5,000 notes. But if I do grep R and if I now want to search for Linux and I'm doing that in the current directory and this is going to show me all of the contain all of the notes that I have in my my note taking system containing Linux. So this is very useful for like even a personal note taking system and you can see how fast this is, right? So I can take all of the the notes that I have containing Linux. You can also count the matches. So earlier we saw that there were about five lines. Well I was actually pretty correct there. It was six lines. So there are if you use the C for count then you are getting the number of lines that match.
-
And next is also this is also a nice one. This is the showing the context. So this by default grep only shows you the line that matches, right? But if you do before and after B 2 and A 2 it's going to show you two lines before and two lines after the error the or the match. You see that? Actually man grep dash A yeah so after contact and then there's also the C flag which is basically showing everything around it. So if we do grep if I do the grep command again but we change this to c and then five. Then it's going to show the five lines that are around the error line that is matching. Now grep also supports it it supports patterns, not just literal text. So these are regular expressions going into the details of regular expressions is a little bit outside of the scope of this course, but regular expressions are a basically their own little language that you can use to filter out text content. That's the best way I can explain it.
-
So if I do grep root etc password, I'm now getting all of the lines that begin with the word root. So this caret symbol means beginning starts with finding lines starting with root. If I do this grep bash dollar sign, it's going to find all of the lines that end with bash. In this case, there's two lines in this file that end with bash. Here's another one. So grep user zero to nine etc password. This is going to be finding find user zero and user one. Well, in this case, we don't have anyone called user one, but if there was a user with that had zero to nine in its name, it would show up in the etc password file.
-
So it's very very simple. It's a very simple way of using regular expressions, but if you if you know these two, so lines starting with something and lines ending with something, you already have a lot covered. Now here is the interesting stuff. So this is actually not a good pattern to learn but this is where um you we are going to get into piping. So if I do cat etc. password like this etc. password cat command is now is now going to output that, right? It's now outputting that to the the terminal. But I can also take that output and pass that to a different command. So if I know do grep bash now I'm getting all of the lines there. Now this is actually not a very um good example of me to give because I can just run grep bash etc. password and I get the same thing. So catting etc. password is actually not a good uh pattern to show you, but I but I want to show you is that I can take the output of one command and then put pipe that into grep.
-
So what would be another one? So if I do the date command for example, date if I want to let's say this this command outputted multiple lines and I just wanted to get the dates of 2025. If I do date and then grep 2025 then I would get only that line, right? I can also do like we said that we had that bash is basically its own programming language, right? So if I do for I in zero to 10 do date done. Okay, so now I am running the date command 10 times and it's actually showing the exact same thing in everyone. Um is there a way I can delimit this?
-
So well let's check out man date. Is there a way to show the milliseconds? No, it doesn't actually here nanoseconds. Okay, so if I want the nanoseconds, I do INS. So if I then do the four loop that I did again, but if I do date INS done. Okay, so now I'm getting a different result for every line. If I now grab this, so grab uh 04 for example. Yeah, so now I'm getting the nanoseconds. So if I then grab this for three, then I'm only seeing the lines that contain three or two or grab one. All of them contain it. Yes, okay. So if I then grab for seven, then now I'm getting only the lines of seven.
-
So what I just did there, this like you don't have to know this, but I'm actually doing a loop inside of Bash. So for 10 times, I'm executing this date command and then I can grab out the lines that it's generating only containing seven. So this is an example of a better example of of outputting something and then finding those results, right? Now let's look into file information. So what type of file is this? So this is again going a little bit back to this type command. We had that for commands. File is the one for um for files. So file bin LS, it will show me that it is an ELF binary. It's an executable. It's compiled for ARM architecture because I am on an ARM CPU. And it's for GNU Linux. So it shows me information about the file.
-
If I do file at C password, you will see it's just an ASCII text file. And syslog is also an ASCII text with very long lines. So it gives me some interesting information about the file. If I want detailed file information, we can use the stat command. So stat etc. password, it will show me the the the when it was accessed. It shows me um the location of it and the actual inode of it. Um we're not going to cover inodes right now. It shows me the permissions. So stat is also a command that will give you more information about a file. So now let's do some fun stuff with uh some commands. So now there's there's the wc command which is the word count command. And if we open up man wc print new line word and byte counts for each file.
-
So this file contains 32 lines, 45 words, and 1,646 bytes. If we just want to get the lines, then we do wcl. And then we get only 32 lines. So that's the only password. If we want the word count then wc etc. password uh contains 45 words. If I do w if I want to get the number of words in var log syslog is 40,000 words in that file. But look how fast that was, right? On a Raspberry Pi. It's pretty amazing. And then this is the character count. So now we have now we know about files. Let's learn about directories. So how big is this directory? du. For this you use the du command. du -sh var log.
-
This one is 33 MB. The current home directory, if I just do du -sh, it's doing the current directory. My current home directory is only 68k uh kilobytes. du disk usage. The s flag summarizes and the H makes it human readable. So, if I do d u s h, it's just going to show 68. And if I do this one, var log, then it's going to show this number, which doesn't make sense a lot. This is the amount of bytes. But we want to know the amount of megabytes, and therefore we do three uh that's H. Now it shows us the megabytes, which is more useful for us humans. You can also do a max depth. And next there is the df command, which is very useful. So df is also one of those commands that you're going to be using a lot. So df is now going to show us the bytes. So again, we want to run that with the df dash H command, which is now going to show the sizes in human readable format.
-
So this is useful because here we see uh all of our devices, our disk devices, and what size we have available. So in our case, we have our temporary file system, and then here is our root file system, which current which which has 53 GB available on it, and we are currently using 2.7 GB. And this is the column to watch use. So if you have a server and the root file system has a usage of 98 percent, then you need then you know that you need to do some actions here. So here's the commands that we have used cat less more tail grep files, stat, and w c, and df. So here's a little challenge for you. And um investigate the etc directory, how many files and directories are there.
-
So this is a bit of a fun exercise. We haven't done this, but you have to combine ls and wc. I've I've shown you how to pipe things. Then find all the files that contain the work work network. What is the largest file in var log, and how much total disk space is used on your system? And there will be hints down below that that will have the the explanation and the solution to the exercise. So good luck, and I'll see you in the next module. Now something really important. You can watch me run Linux commands for 8 hours straight and still not learn anything. You need to practice. You need to put your hands on the keyboard. That's why the course comes with hands-on exercises. Try everything yourself and then check whether you got it right. They're free inside the Linux community. It's the first link in the description below. Now let's keep going. Welcome to module six, where we're going to be learning about text editing with VI. And this is one of my favorite topics to talk about. If you've seen any of my videos and and even just this course, you see that I am using VI [clears throat] or technically Neovim in this case. I am using it this VI to edit files in the the the terminal. And in this module, we're going to be answering the questions why you should even learn VI, what's the difference between VI and Vim, uh how to open files, how to edit files, etc.
-
So the first of all is why VI. So if you're watching this, it's very likely that you know well you know obviously know me as a YouTuber, but you've also seen videos of Typecraft, the Prime Agen, and many other big YouTubers that use VI or Vim, right? And VI is it's not just a meme factor or it's something to access if you're cool. No, it has a very specific application to you if you want to become a system administrator or a DevOps engineer. The thing is that a VI is an text editor that you can use from the command line. That is one important thing. So so far we have been we on this course, we are purely focusing on the command line. And now we have seen how we can um like get the head of files.
-
So head of every head of files and get watch the content of files, but we haven't learned how to edit files yet. So we can search files with grep, we can get information about files with stat etc. But how do we actually manipulate the content of those files if all we have is the CLI? If everything we have is a uh terminal, how do we edit files? Because we can't just double click if I am in my home directory, I can double click on hello.txt and Microsoft Word opens and I have a place to edit. It doesn't work that way. I need to be able to to edit these files from the command line but because if I cat my hello.txt it currently does not have any uh contents. So how do I edit the files? Well, you run a command that allows you to edit those files and the command for that is vi.
-
vi hello.txt And now you see I am opening an editor. In the bottom it shows me the the it shows me the name of the file and now if you know if you know what you're doing I can now edit this file. And I'm going to be teaching you how to do this from the command line because now if I cat hello.txt now we see that it has the content. I can now edit this file. So vi hello.txt we see that the contents are there. So that's what we're going to be covering in this module. So if you are a little bit familiar with Linux and yeah Linux and DevOps in general, you will know that vi is not the only alternative. There is also something like nano. So if I do which nano there will be an an an an a program called nano and actually I have I don't hardly even how to edit text files with nano. So, nano hello the txt.
-
Yes, okay. Nano is also a way. And let me see how does this work. Can I now go Yes, um uh I wrote this with nano. And if I want to exit, I think it's control x. Save yes. Enter. Okay, and if I now do cat hello txt, yes. Okay. So, nano is a different editor. So, nano, you might have heard of this, is somehow is nano is actually the the default editor on Ubuntu. So, echo editor Oh, it's actually unset here. But nano is usually the one that we you will see in beginner tutorials, which is very strange to me because VI is the standard editor on Unix systems. Like every Linux distribution, every Unix system, macOS, and even minimal Docker containers always always include VI.
-
But they will not always include nano. So, if you want to become an engineer that can log into any system in the world and be able to edit text files and make modifications, you have to learn VI, not nano. And this is a strong statement, but I'm like I I was taught this in the beginning uh do VI and don't look at anything else, not Emacs, nothing. So, I had very I have a few very good mentors in my career. And the people that I respect the most in a technical fashion, the most technical accomplished persons, the most senior persons I know, they all of them use VI. All of them. And to me that is enough proof that the the people who really know what they're doing, they will use VI. If you are a system administrator and you've been working for 20 years and you don't know how to use VI, you have done something wrong.
-
So VI is the one to learn. And I'm just going to stop ranting now, but just to prove the point, if I just do a podman run IT Alpine on my main system, you don't actually do you don't you should not do this, but I am now in a Alpine container so cat at C OS release Alpine Linux. If I do D U S H pseudo D U S H uh yeah D U S H you see that the root file system of this container is 9.6 megabytes. That's how small it is. But if I do which Nano or which VI, you'll see that I have user bin VI. So I can if I go to a home directory, I can do VI hello and I can enter some text. This is in Alpine.
-
And if I then cat hello, you see that this is in Alpine. I have edited files inside of a container. So it has 9.6 megabytes to run this operating system. But VI is here. If I do which Nano, it's not there. VI is going to be available in any container in well not any but in any system that is in any shape or form um allowing people to SSH into it or to interact with it is going to include the VI editor. And that's why you learn VI because you want to be able on every system that you are working on, any virtual machine, any laptop, any container, you want to be able to edit files. So in this case, if I'm in an Alpine container, which the Alpine base image is used I don't know, millions of projects. So, the Alpine base image is a extremely widespread image.
-
This does not contain Nano. So, if the only editor you know is Nano, then you have a problem if you're working with Alpine containers. In other words, a lot of the containers that are running in the world like proper properly designed Alpine containers are running on the Alpine image because it's so minimal. Okay so I'm going to stop ranting now. Just learn VI, just do it. And in this in this module, we're going to be learning about VI. So, VI Vim what is the what is the difference between the two? So, if we do LS LA, if we just first start with which VI, we see that there's a user bin VI. Okay, so that looks pretty good. But then if we do LS LA user bin VI, we see actually that this is a link to Etsy Alternatives VI.
-
So, if we then LS LA at C Alternatives VI, then we see that it is actually linked to user Vim basic. So, when I run VI on my Ubuntu server, it is actually going to open Vim. Now, what is Vim? Vim is VI improved. So, we can actually just do man Vim. Vim Vim VI improved, a programmer's text editor. So, Vim is a text editor that's upwards compatible to VI. It can be used to edit all kinds of plain text, especially useful for editing programs. So, there are a lot of enhancements above VI. So, there's multi-level undo, multi-windows and buffers, syntax highlighting, command line editing, file completion, help, etc. So, there is a lot of different, a lot of differences with um VI. VI is the original program. It's based on ed, which is even more old school, but you have to go back to these big systems that we talked about, right?
-
These massive computers with multiple users running on them from a terminal like this. Well, people used people write wrote programs on this. Like most of the software that we've been working with up until now, like make dir etc. has probably written on machines like this using only the terminal and the command line. So they needed to be able to edit text files. And VI is one of the like ed is what is the original, then was ed x and then came VI. And VI is the the the one of the original editors that these people were using. So there's a difference between VI and Vim, where Vim is Vim improved and which is a yeah, a little bit more fancy um uh version of VI. And not that this what you see here looks very fancy, but what you see here in this window here for example, this is then NeoVim.
-
So this is the new iteration of it. And NeoVim has all sorts of cool functionality. So you see that my markdown is all nicely rendered. I can search for files here. I can do I can, you know, search for my video output etc. So there's tons of code that I can use here. And this is a more it has colors. It is much more what do you call it? I can navigate through all of my projects using files etc. So it's much more modern and has much more functionality. But the cool thing is that I can use this neovim because I started with VI. That's what I did myself. I got the advice, learn VI. So for several years, all I used to edit text in my note taking, programming, everything, only thing I used was VI or Vim.
-
So now we know that when I run VI hello, this is the actually just running Vim on on my system. So I'm not actually running VI here. So in order to get VI on our Linux box, we have to do we have to install something different which is called busybox. Now busybox is a binary that contains a few tools in it. So busybox is a single executable. It's a single command that provides stripped down versions of many Unix utilities. So this is used in Docker containers, it's embedded systems and rescue disks. So in other words, if you do man busybox now, no, it doesn't show busybox help. Well, it says anything. A multi call binary that combines many Unix utilities into a single executable.
-
Most people create a link to busybox for each function they wish. And yeah, so as you see, there are a few commands here like ping and does it have NS lookup? Yeah, NS lookup. It has all sorts of useful commands. So if you are like like a rescue system or a router, etc. If you just want to install all of the useful commands and have one package to manage, then busybox is a good one. So if we then use busybox VI on a file. So here we have busybox vi hello txt. Then now we see that we have a different um now now we are actually running vi. Now how do I see that? If I open up a new one here and if I ssh if I vim hello txt then first of all we see that we have a bit of color in these. So these tildes, these symbols means empty lines.
-
But here we see that there is no color. So that is one way to see it. This one vim also has a bit more information here. So when I move around it shows me the line number and the word or the character that I'm on. vi does not do that. So in in this one you see less information. And that is in general the idea with vi. It is even more minimal than vim. vi was the predecessor of vim and vi is like you can hardly get more basic than text editing than vi does. But now we have a way of um and we have a way of running vi before we're going to move on to vim. So if I another difference is um here. So vim uses modes and we're going to be getting into that. But if I now press I then insert below here it says insert. I am now inserting.
-
And if I press escape to in to remove it. But if I go into insert mode here then all I see is an I here and I don't see it and I don't see the insert. So that's also a way how you can see if you are in vi or vim. Okay. So let's well we already we're going into it so let's now go into modes. So vi has two main modes. And for the record I'm going to close this window. So everything we are doing is now going to happen in VI. So um every time we are going to be opening a file, we're going to use busybox VI hello and then we are sure that we are actually running VI. VI has two main modes, the normal mode and insert mode. So this is a new concept for when you are doing doing any text editing from the command line. You have to get used to that you are in two different modes.
-
So normal mode is to navigate around in the file and to run commands and then insert mode is for actually inserting text. So the most common mistake is trying to type in normal mode. So if I open up busybox VI hello txt if I now I'm just going to delete everything here. So you now see that there is a dash here. If I press I then you see that this changed to an I and that's how I know that I am now in insert mode. So any keystroke that I do and the and I can move around with the arrows, the arrow keys, but otherwise all the keys that I press are going to be inserted here. Now if I want to exit insert mode, if I do escape you see now I'm here I see a dash. I am now in command mode and if I now for example press H or K J or K. So J going down, K going up.
-
I if I do this in command in normal mode or command mode I am now moving the cursor around. But if I press I to enter insert mode, if I do JJ KK JJ KK I am actually entering the text. If I escape again, jjj kkkk jjj kkkk, I'm now moving around. So, there's two different modes. It's insert mode to actually I am now in insert mode. And if I press escape, I move around. I can run commands. So, that is the main difference. Let's do our first edit. So, go starting completely from scratch. I'm going to remove hello txt Sammy world. I remove config. So, we are completely clean again. Everything is clean.
-
So, let's make our first edit. So, busybox vi text.txt. Okay, I have opened up vi and then press i to enter insert mode. Hello, this is my first edit. And then you can exit it. So, I'm here. I press i. This is my first edit. Press escape. Escape, escape, escape. You see on the bed here I am dash, not an i. And then what you're going to do is you're going to type the colon. So, here you see this symbol colon w q. Colon w q and press enter. If I now do cat test txt, then we see that this is my first edit. So, one of the biggest memes is to how do you exit vi?
-
Well, that is how you do it. You type colon w q enter. And that's how you exit it. So, again vi busybox vi test txt. I'm going to do insert mode again. This is another edit. Period. Press escape, colon, w, q, enter. And I exit it. Cat test. This is another edit. I have now successfully edited files from the command line. So, in normal mode you do command w, q, and that means save and quit, write quit. Let's open it again. So, busybox vi text test.txt and I'm going to press insert mode and now I am writing something new dot.
-
If I now press escape and if I do colon w this has now written to the file. Right? It is now written in something new to the file. So, if I do now I can do colon q and I can exit. So, if I do cat test.txt, I am writing something new. Let me open it again and let's add something. This is not going to be saved. If I do escape and then colon q it's going to say no write since last change. So, it detected that there were a few changes, but I haven't saved. But if I want to yeah, okay, it's fine. I don't want to actually uh save that, you can do q exclamation mark. It actually tells how tells us how to do it. And if I now do cat again you see it was not saved.
-
So, that those are the few ways of exiting. So, you you when you're working in your file and you write then you are saving the file. If you want to quit, you do colon q. Save and quit is colon w, q and Q exclamation mark is to quit without saving. Now let's um learn about navigation. So I am now in insert mode in normal mode. You see the dash here in the bottom. In normal mode you can navigate with the arrow arrow keys like this and that is completely fine as a beginner. Don't worry about it. But there's also H J K L. So you can navigate in Vim with H J K L. So J and K J to go down, K to go up, L to go right, and H to go left.
-
H J K L. So this is Vim navigation. This this may feel very counterintuitive, but the whole course you have seen me navigate this file and I've hardly used the mouse while doing this and I do all of this with the H J K L. Every time you see me moving here I'm doing that with these keystrokes and that means that I don't have to like pick my hands up into the mouse and back. I'm actually I can just navigate my whole system using my my keys. So the same if I am opening uh a man page, so man LS, you can also do J K down here. And you cannot do H, but J and K these are actually uh almost any program in Linux will have this H J K L. And you will find that also other programs that have nothing to do with text editing will find that J and K will scroll up and down. So these Vim key bindings, these navigation shortcuts that we're using you will find that these are available in many different unexpected places.
-
So I highly strongly recommend that you learn how to navigate with HJKL, but in the meantime, you can also just use your arrow keys. That is completely fine. Now, entering insert mode. We've already um seen how to do I, right? Normally, you open a file, you press I, and now I am at the beginning. But that is not very useful because you don't always want to be at the beginning, right? I'm opening a file. Let's just quit. Open it again. So, I this is my new file. What if I want to write a new line? Well, what I do is I press O and then I enter insert mode on a new line. So, I am now on a new line. Escape. And I can now navigate around, blah blah blah. But let's say I am on this line. I want to end I want to um add a new line. I just O. And I can even just enter a few times, and you see then this character disappears.
-
So, this is not an empty line anymore in that sense. These are completely empty, but this contains Let's call it an enter for now. It's correctly it's the line break, which is the right term. But let's say this is a new line at the bottom. And I can escape. And I am now I can now navigate around again. So, let's save this by colon W. And this is now saved. So, you can enter insert mode. So, if I am here and if I want to if I want to enter the word beautiful here, now I can press I. And then I I enter insert mode where the cursor is. So, new beautiful line. Escape. And let's move at the bottom. And now I can press I, and I can do space off the file, something like that. Escape. So, this is how you can move around and and add words and characters over here on the bottom of the file, something like that. See?
-
So you can move around, press I to start editing where you are. And if I am here and I want to add a new line below, it's O, this is a new line. Let's learn how to delete things. So deleting, if I navigate around and let's say I want to remove the L here, I just press X. X X X X X X X. So everything under the cursor is going to be deleted when I press X. So I can just go here and delete random characters like this. Now if I want this is this is of course useful, but if I want to delete a full line, you can do DD. So in command mode DD. This is how you delete a full line. DD DD DD DD. So just write DD like this and then you delete the whole line. And then if you want to undo, you can undo like this.
-
And actually VI this implementation of VI has more undo than normal. Um but on on truly minimal systems you won't be able to undo so far. Now there is also the possibility to search inside of a file. So let's say I've been working on this file. It contains a ton of text. I have been working very very hard on this. And this is the end of my essay. Learn VI by the way. And again I'm we're all doing this in a simple text editor that is a few bytes right large, right? Now let's say that I want to search for the word work here. Again we've already learned this in our man page search. So slash work enter.
-
And here it's it's going to move the cursor to the first result of this. If I press n, it's going to go to the next one. And it's down says in the bottom search hit bottom continuing at top. So I'm searching for work and it's now going to cycle through all the results. Let's search for VI. Oh, there's only one. But I see I added the the capital letter there. What happens if I just search for VI? Then it's going to say pattern not found. Even though VI here is here. Then we actually need to have it it's actually um matching the case. So if I want to search for VI, then now I can find it. If I go here, then uh actually I do that by pressing GG. So GG like this. That goes to the top of the file GG.
-
If I want to go to the bottom of the file, I press capital G. So shift G. GG shift G. GG shift G. [snorts] And if I'm at the top and I want to search for by the way, then I find only one over there. So you can search in in inside of VI. So here this is the the most minimal primer on VI that you are going to encounter probably. But this is all you need. This is truly all you need to know to edit stuff with VI. So the minimum you need I for entering insert mode. In other words, start typing. Esc to stop typing. Colon WQ to save and quit. Colon Q exclamation mark to quit without saving, delete a line and U for undo. So with with just these six commands, you can edit any file anywhere.
-
And this is all compatible with Vim as well. So, if I escape this, if I now do Vim test.txt, now I see that I have a little bit more color here, but everything is the same, h j and let's o enter insert mode. I I am now writing text in Vim. Now you see in the bottom here that it says insert. It's a little bit bigger and these have colors. So, that's how you can see that you're in Vim. But that is basically uh it's all basically the same. I can search for let's say work. Now what's different is that it actually if I'm doing this like work, it's already highlighting it. You see that? Or very, that is like a nice little extra function that you get inside of Vim instead of VI. So, it's these little things that make it make a difference. So, from now on we're going to be using Vim in our course probably, but now you have the skills to tech to edit any file wherever you are, even in a busy box container. So, if I again podman run Alpine, if I go to Etsy and I need to edit my hostname, I just do VI hostname and then I can change this to uh my host.
-
And now my hostname is it's not propagated, but if I do cat hostname, it's going to contain uh my host. If I need to edit any sort of VI sysctl.conf, VI sysctl.conf here, this is a um config directory I can of config file I can add stuff in here and configure everything with that from the command line. No need for graphical interfaces or or like that. So, VI what just given you is a skill that is going to is going to be so important for the rest of your career. So the test is test this a lot. Do work a lot with this and do the little exercise that I've added to you. And the last thing that I want to give you is the command Vim Tutor.
-
So Vim Tutor is going to say it it doesn't exist, so you just say enter. And here, welcome to the Vim Tutor. Vim is a very powerful editor that has many commands, too many to explain in the tutor such as this, etc. So make sure your caps lock is not depressed and the J key enough times to move the cursor so that 11 lesson 11 completely fills the screen. And you can just move the cursor and then here lesson lesson 1.1, I'm sorry, not 11, is now in the screen. And here it's going to tell you to move the cursor, press H J K L as indicated, right? So what we have learned. Next we can go to the next lesson, exiting Vim. Press colon etc. So Vim Tutor is a program available on any system that contains Vim. In this case, our minimal Ubuntu server that's taking 200 megabytes of RAM. We have everything we need to learn Vim.
-
You don't need courses, you don't need you don't you don't need to pay anyone to learn this. It's all here. And what I recommend is that you now for the rest of this course and for the rest of your career, run the Vim Tutor command once a week until you have mastered Vim. So there's like like it's pretty big. There's quite a lot of it in here, seven lessons. And you definitely don't need to know everything that's in here, but it's such a good way of practicing because it's already here. You you have the command line. It's on my Raspberry Pi or my virtual machine. Vim Tutor and it will walk you through it. So, after you've completed this lesson and you're going about your week, once a day, just run the Vim Tutor command and go through this um the command. It will teach you everything you need to know about Vim, but this is the minimum you need in order to be dangerous with VI.
-
So, practice those, run the Vim Tutor, and now we can move on to the next lesson. Welcome to module seven where we're going to cover users, groups, and permissions, arguably one of the most important um pieces of your Linux journey because you are going to be as in your career as a DevOps engineer, you're going to be encountering this almost every single day, especially when you start working with containers. So, it's important to uh to understand this properly. So, we are going to be answering the following questions and uh let's dive into it. So, first of all, let's try and figure out who we are. So, we already see that in the prompt, right? But let's say we don't have a nice prompt like that and we are on a system that only shows uh the status line, for example, then we can use the command who am I? Very simple to remember, who am I?
-
The next command that you can use is who and this shows a little bit more information. And if you say W, then it shows you even more information. So, there's a little bit of a funny joke there where the shorter the command goes becomes the more information you get. So, who am I? Who and W all show information in increasing uh fashion. So, what we see here in let's just clean it up and let's do W then. So, here we see that the um if you do who am I, then you just get your own user, but the who command actually shows which users are currently logged in on this system and it will show the source IP. So these I have two sessions user in the device is PTS one and we can see that LS. We saw that everything is a file, right?
-
So dev PTS PTS zero. We see that this is a device. So stat dev PTS zero. And we see that this is a file in the dev directory. And this is the information about it. So the actual session that is shown in who is represented as a file on the Linux file system. And if we then do W then we can also see um how long they have been idle and how long they have been logged in. And the reason there are two is because I have two sessions. I have this window open here and I have one over here. And if I now exit this and if I run the W command again now we see that there's only one session active. So that you can see um the more information about your user but also other users logged in to the system. Now let's check out the ID command. This shows you a lot more information.
-
This shows your user ID number. So in in Linux every user gets its own ID, its own number, a numeric representation of the of the user. It and then it shows your primary group ID. So there are two fundamental principles. There's users and there are groups. And users are members of groups. And you need this because if we um if you're managing multiple users so let's say these are all users then we're going to give them permission to do certain things or to access certain files. Now it will be very annoying if I had to set those permissions on every user individually, because then I would say, okay, this this person is, let's say we have file one, file two, and file three.
-
I could say this person is allowed to access these files, but these persons are not. I can I can say that, and we're going to learn how to do that. But if I were to if I were to say, okay, everybody can access these files, then I would have to say, okay, this person can access those files, and then this person can access those files, and then this person, and then this person. So you have to assign these permissions individually. Well, that is of course a lot of work. So that is why groups were invented. So let's say we have a group, a group let's call it the file group, and we're going to say, hey, everyone who is a member of this group is allowed to access these files or this device or whatever you are giving access to. Everybody who is in this group, you can do that. And now all I need to do is to just assign the members to that group, and then automatically these people are able to access what I want. And this is a pattern you will see in cloud computing, managing users in other systems. Um the the concept of a group and setting permissions on a group level, you will see in many many different places and applications. So it's an important concept to know this because now I can let's say we have a junior engineer and juniors are not allowed to access these files, but after two years of working in
-
the company, he is now promoted to senior, and now he can enter the senior group. Let's call this the senior group. And now all he can also access these files. But let's say someone uh was working on the senior level and now he goes to management, well, we don't want him to have still have access to those files. And instead of having to remove all those permissions for this user, we can simply remove him from the group, and now we can be sure that only this people in this group are able are allowed to access those files. So that is why their groups exist, because it makes managing permissions easier. So this ID um command shows me my user ID and my main group ID. So each user gets its own group as well, and then there are other this groups um object here is going to show you or array technically.
-
It's going to show you which other memberships I have of groups. Now another command to do that is the groups command. So groups is going to output the command the the memberships that the current user has. So I'm running this as user user, and if I run the groups it's going to show me um the groups that I'm a member of. And you will see here that I'm also a member of the group ADM and sudo, and that is why I can run sudo test commands like this. I can run I can can run commands as sudo. If I was not a member of that group, I would not be able to do sudo. So every user has um a username like John, and an ID number like 1000. He has a home directory and a default shell.
-
And we've seen that in the etc password file earlier, right? We we were um doing it. So if I do cat etc password password WD, then we see in the in the last line we see exactly what is said here. So a username, the user ID, the group ID, then his home directory, and the default shell. And I remember this is how the system knows which shell needs to be executed, right? And you can also see here that there are also certain users on this on this system that have the shell user as bin no login. And this means that this user is not actually meant to be a user. It's more like a system service. So we need a we are running a certain service on our system and he needs they need to have a user because we want to manage the permissions in this case of polkitd or message bus, whatever.
-
And but we don't want anyone to log in as that user. And that's how you set you can manage that by setting this no login shell. That means you cannot actually log in here because you cannot get a shell because remember you need a shell to be able to execute commands and talk to the kernel. Again, so if I do this grep and then bash get grep bash and then etc password. And we see there are two two users in my current system that have a that have access to the shell, in this case bash. So there's the root user and then the user user, my user. These two have are able to create shells and and have interactive communication with the kernel. And all of the users are stored in the etc password file. So you'll be you'll be using that file a lot.
-
Now the x here means that the password is stored elsewhere in etc shadow. So let's check out what that is about. Cat etc shadow because obviously you don't want to store those passwords in a file. So if we do sudo and remember do you remember how to run the last command as sudo? Try to remember there was a shortcut for that. You do it by doing bang bang exclamation mark here and here we see that there this will show me a hashed version of the password that is in etc shadow. So this is not the actual password but this is a hashed pass password. So it is the data is transformed based on a seed so that you cannot just read it from clear text. Now let's check groups. If I do cat etc group then we see all of the groups that are on the system with their user IDs and there's quite a lot here.
-
So the difference here is that groups the out groups is the output the output of this shows me the groups that I'm a member of but you can see for example RDMA is a group that exists on my system RDMA but I'm not a member of that group. And that is because I don't need to be in I don't need the permissions of that group or the administrator of this system does not want me to have those permissions. Now let's then try to add a new user sudo add user test user and then it's going to select a user ID. It's adding a new group for that user and it's creating a home directory for that user. So my new password let's do just do password and now it's going to ask me for my full name etc and this is of course a little bit legacy and to be honest you're not going to be using as many different users on a system these days actually for actually logging in but I'll get back to that in a second. So let's just do the full name, Michel VanDenBerg.
-
Room number, right? So this is, you can see how this was meant created for like schools or businesses, but you can just do enter, work phone, home phone, other. Is the information correct? Yes. And here the capital letter shows the default option. So yes. And now the new test user is added to the system. So let's just go back to why you would need users on a system. Well, going back to this situation where you have multiple people sharing the same computer, well obviously you don't want everyone to be working in the same identity, right? You need to separate out. And actually back in the day you had to, in many situations you had to pay for the computer usage you did. So one of the earliest use cases, mainstream use cases of computers was that accountants, people who work as accountants, they would go to a place where a computer was available and they would have to pay like up until like $100 an hour to use that computer. They would run their programs and their spreadsheets, but it was worth it because it saved them days of work. So they they did that. But they also needed ways of calculating the usage of that.
-
Likewise, you don't want everyone on that system to have access to your files, right? So computers originally were multi-user systems. And again, the personal computer is a relatively new invention. Like it was not the case that everyone had their own computer before. Computers were big systems with multiple users and in some cases thousands of users. So a system administrator was the person who was responsible for managing this system and making sure that Johnny here is not able to read the Lambert's files over here. We want to separate those and we want to keep track of if if Johnny is using more of the computer than he does. So that [snorts] is why you need multiple users on a system and these days people usually tend to just have their own computers, their own servers. So it's not very common to actually have a multi-user system anymore, but you do need users for running services on your machine.
-
And you want to For example, if I run a a certain program on my system, I do not want to have that to have sudo privileges, right? So in that case, what you will see is that you run a that you create a user for that, give it certain permissions, and then it can it can do what it needs to do. Likewise, and we're going to get into this in containers in the next course, but we've learned about the root user that has privileges that Well, you don't want to be running applications as that user, right? Necessarily, you want a different user that does not have the the complete power over the whole system because if your application gets hacked and if that that is then being run as the root user, the root user has access to your entire system. So you want to close that off. And you do that through permissions and creating users.
-
So we've added We've created a new user. And if we then check out the etc password file again, then we see that we now have my test user, my user, my main user, and then we have the test user, in this case Misha Vedenberg, and his home directory is in /home/test user. And the default shell of him is bin bash. Now, if we check out the home directory now, we see that there are multiple home directories here. So, this is the convention that the home directory, so your slash home, and then when you create a user a a um home directory is also created for that user. So, what is the home directory? Well, the as again this multi user system, right? You the people using the system do need a place for their own files. Like they everything that is that belongs to them.
-
So, we in what in in in uh um in many ways we like you have your root file system, right? Well, we don't want anyone just putting files all over this and it would just become a huge mess. Likewise, there is the issue with permissions, right? So, if there these permissions here the user is the owner of this, so we don't want to uh if I do LSLA slash, we see that the the we're going to see what this means in a second, but we see that these are all owned and managed by root, right? So, we actually people cannot put their files in there. We don't want anything to be spread over the file system. So, everyone gets their own home directory and for me uh the my home directory is in home user and this contains the files that I use that are that belong to me, my personal configuration files, the things that I want to store, that I want to save, the programs that I write, all of that lives in the home directory of the user.
-
And this is also a convention that I'm going to teach you that um if you're going to go into this Linux journey, you're also going to be um needing to learn how to back up your system, and that you're also going to be, you know, changing Linux systems a lot. You're going to be installing a new distribution, you buy a new computer, and you are going to change things around. Well, if you make it a habit to put all of your important stuff always in your home directory, then you know that first of all, if you want to make backups, all you need to do is just back up your home directory, make sure that it's copied somewhere on a USB stick or whatever. And secondly, you know when you switch a system that anything you want to keep is actually in your home directory. So when you're working on any system and you're thinking I do not want to lose this, put it in your home directory and you'll thank me later. Now we have this user, but we're not going to use it that the that one right now, so we're going to uh run the del user command, sudo del user test user, and now it is also removed. So if I now do LS home, we see that his home directory is actually still there. So if you want to remove the the the user with his home directory, you you have to add the remove home flag. This is not going to
-
work because test user does not exist. So what we have to do is we have to go to uh CD home, and then we're going to do uh RM R test user. Permission denied, so we have to do it as root, sudo. And now our slash home directory is nice and clean again. Now how did this happen? So we said I said cannot remove test user, permission denied. So what is that about? What is what are permissions and how is this actually implemented where you block people from accessing and managing other files? Let do an LS L at C password. Here we get one line, right? And this line, and this also is similar to if we would do ls la etc, for example.
-
You see all of these lines. Each line is its own either a directory, as you see here of the d, or a file, right? But there's a lot more going on here than just that. So that is this we're going to dissect one of these lines. So ls l etc password. So what what does the etc password look like in the in if you were to ls this? Let's break this down. So the first line here is the file type. So we already learned that a dash is a file, d is a directory, and l is a link. A link is a what you maybe would call a shortcut in in Windows. The next here is the owner permissions. So this this little line here is broken up into several sections. We have the the you the user of the the owner permissions, the group permissions, and the other permissions.
-
So the owner is the the user who owns the file. Then the group is everyone in the file's group, and others is everyone else. And for each of these we can set the permissions, right? So the permission types are read. So any if anyone has read permission. So in this case the owner here, so the first the first block here, we know that the owner is allowed to read this file. In this case, root is the owner, so he's a he's allowed to read it. The W stands for write. So the root user can modify the contents. He can add or delete things. So the root user is able to is allowed to modify this file, right?
-
Next, there's execute. Can run this file as a program. Well, we see here there's R, we have read, we have write, but there's a dash where we would um deny the execution of this this particular file. So what does that mean? If I go to CD user bin, here we see this user bin directory that contains a lot of um commands, right? We learned that. If I do LS LA here, we see that all of these but um commands, these are all commands like the who, who am I, etc. We've seen that, right? If again, if we do let's do the who command as an example. So um command V who is is located in user bin who. If we then do LS L user bin who, now we see that we have a a different picture than what we see in LS L at C password.
-
Let's combine these two. Let's compare these two. So the at C password is a file. We know that this contains the users and the group information. We've been working with that. Now the user bin who is a command. We we can run that. We have been running that, right? When you when I type who in the shell, bash is going to find the who location and then it's going to execute that. So who is an executable? It's a binary, it's a program that is made to be executed and then the execution of that is going to perform certain actions. That is what a command does. But in order to be able to execute this because this is just a file on my system just like etc password. And remember how did we how did we do it? We could do type and then user bin who. User bin who is user bin who. If we do stat user bin who then we see that it is a file, right?
-
If we do stat etc password oops stat etc password we see it's a file. So both of these are files, right? So let's do let's clean this up again. Clear and LSL user bin who LSL etc password. Both of these are files, but you see in my syntax high in my color in my terminal that there's a difference between the two and the difference is over here. So the root user again going back to this overview here it's these sections here. Each little section here uh represents the the the position here. So right the permission groups. Each section here represents the permission groups and each of them each of them has three elements r w and dash or x.
-
Read write execute. So here we see r w x. So the owner of this file because we know it's the owner because it's the first block the owner of this file is allowed to read it to write it and to execute it. See? Now the the the the groups of that have access to this file are allowed to read it and to execute it, but they're not allowed to write it. You see? It's missing the W. So only the owner is allowed to write to this file. And finally the others, the others block are also allowed to read and execute this file. So that is why if I do cat etc bin who, and this is going to output a lot of um user bin who, this going to output a lot of gibberish because it's a compiled binary.
-
But I am able to read that file, right? And I'm also allowed to execute that file because I can run the who command. It's running. If I type user bin who, it runs. I can also just type the full path like that. So that is the how these permissions are showing up in the LSL. So now we know that we assign permissions in this little block. But how do we know who is the actual owner? Well, that's how we see that's what we see in the next blocks. So let's LSL etc password. Here we see the owner and the group owner of this file. Right? So if we go to my home directory, oops, CD. And if I'm not here doing LSL A, then we see that most of these files are owned by me. You see?
-
The dot profile file is owned by user and the group user and the owner is allowed to read and write this file, but he cannot execute it. And other people are also allowed to read this file. Now the dot SSH directory, we're going to learn about this, but this contains sensitive information. So this is a directory which is allowed to read, write and execute and directories always need execute permission in order because so that you can enter it. You will always see execute on directories. But the the SSH directory should only be accessible to this user, to the owner of the directory. And that is why you see, okay, we have the first block, this is a directory. Then we have the first three ones that is rwx. So the owner is allowed to read, write and execute. But the group owner is not allowed to do anything and the others are also not allowed to do anything with this. You see? And that is how you can limit the permissions of these files and uh anything else.
-
So this whole whole output is the owner of the file, the group owner, the size in bytes, the last modification date and then the file name. Now we can also um change permissions to things. So if let's say that I for some reason uh there is the the text.info file, text.txt. This is just a simple text a text file. But if I'm going to be creating scripts, scripts need to run as commands and we're going to be learning about that later in the next course. But if I want to execute this file, it will need to have executable permissions. So I can do chmod and then plus x text.
-
txt. And if I if we if I then do ls -l text.txt, now we see that it has added executable permissions to that file for all of the user all of the users. Note that that it is adding it for all users. So I'm not this you have to be careful with the plus x command because if you're on a multi-user system, you're now saying that everyone on the system is allowed to execute this. Well, maybe you don't want other people executing your scripts, right? So that's why you have to be careful. So you can add executable for the um for everyone, but you can also do + UX. So let's see if we want to remove the executable um remove read for others. So you chmod o-r.
-
So let's do chmod o-x text.txt. Now we see that the permission, the x here, is removed for the others, right? You see that? If I create a new test file, so touch test2.txt ls -la. We see it also shows up like in my here. So the default permissions of this are read write for me, read write for the own group owner, and read for others. Now let's say I just want to add executable permission for my own because we saw here chmod + x. It added it for all users. But if we want to do it for the current user, we do u + x. So chmod u + x test2.txt. And if I then do ls l text.
-
ls -l text test 2.txt. Now we see that it only added executable permissions for me and not for the other ones. So you can play around with this and again, so it's the user, the group, and the others. And the a adds all, + adds the permission, - removes the permission, and = sets exactly. Now we have seen these um rwx, rw, read, write, read only, etc. These can also be represented as numbers and you will see this very often in um in documentation, um tutorials, etc. They will very often say uh ch mod 600 and that that is equivalent to read, write for the owner only, right? ch mod 755 is a very common one.
-
So it's executable by all. ch mod 700 is a private directory because it's rwx but nothing for for anyone else. See? Now you can also change the ownership of a uh of a file. So if I go here in my home directory ls l we have test 1 txt. It's owned by user. If I now do ch own root test txt uh I actually have to do that as root. If I now do an ls l, now we see that the owner of test txt is now the root user. And let's see if I now uh want to cat that file I'm a I'm I can do that because I'm allowed to read it, right? Because it is still the user. I'm still in the the the group owner is still allowed to have read, write executable permissions and also the rest of everyone is allowed to have uh um read permissions to this file.
-
But if I want to uh change the owner and group, so let's do ch own root root and then test txt and run it as root. If I now do ls l again, now we see that it's root, root test txt. Let's see if I can cat it now, if I can read it. Yes, I can still read it. Why? Because the permission is still read for others, right? So, if I now do sudo chmod others minus read test .txt. So, I remove the read permission for others. If I now cat it, I'm getting permission denied. The system works exactly as as intended because you see here LSL earlier it was it had the R, but if I do LSL now, we see that the owner is root, the group owner is root, and only the root the owner and the group owner are allowed to do anything with this file. We have removed read permission for others, and therefore I cannot see the content of this file.
-
And that is how you can restrict uh permissions here. So again, let's do a a another test. So, let's do a wait, let's add the test user again. And we're going to add a secret file to the temp directory. Um oh, we're going to add the user, so uh okay, and we're just going to enter that. Correct. So, we now have a user called test user in our um in our system. Okay? Then we're going to run echo this is my secret, and we're going to put that in the temp secret txt file. And we're going to learn about how this redirection works later, but now we have a uh text file. And if I do cat temp text or a secret, I'm sorry, it shows me the contents this is my secret.
-
If we chmod that, so 600, so let's say what see what 600 again. It was read and write for the owner only. So chmod temp secret like this. If we then ls l temp secret we see that the permissions were applied correctly. The user is the owner, the group owner, and he is allowed to read and write. So I can still cat my temp secret txt. I can still do that. Now we can try to read it as the test user. So we can run the command sudo u. So first we're going to be the root user and then we're going to change the user to test user and cat that file. So we're going to run this command as the test user and we see oh permission denied because he is not allowed to read it. Cannot read your private file.
-
If we now make it readable by others 604 and then run the test user command again, now he is able to read it. This is the permissions in in action. So let's remove that file and also remove the test user and also remove his home directory and everything is nice and clean again. So we've talked about the root user already, but let's just go over it one more time. Root is also called the super user. He has a UID of zero and can do anything. So let's check out how can we find the user ID of the user root. Where can we see that? Think of that for a few seconds. The answer is etc password. So if we do cat etc password then we see the that the root user here has ID zero.
-
Now try how can we get the how could we do that without using the cat command? How can we filter out the root user from this file as a little exercise. You do that by doing grep root and then at c password. And now it's only going to filter out the lines that contain the word root. And here we see he has a user ID of zero because if I grab for user at c password, we see that I have user ID 1000. The root user can read any file, can modify any file, kill any process, and change any setting. So root ignores all permission checks, and that is why it's dangerous. So now you understand if you are running as the root user, these permissions don't apply to you. You can do anything anywhere. So if you are run you can you can actually change to the to the root user by doing sudo -i.
-
And now you see the prompt has changed. If I run the who am I command, I am now root. And now I can actually do anything I want. You also see that this symbol has changed. It is now changed to dash. So I can do anything I want on the system. I I could go to here. I could rm rf slash and I could delete everything that I all my system. But this is not recommended because one typo is can destroy your whole system. You can have malware that have full access as root. You have no protection against mistakes. We have already seen that you can easily just remove a directory without any prompting. And so it's against best practices. So the best practice is always to run sudo before any command that you want to run as an administrator. So you've noticed that when you run sudo commands quite a few times, then if I do sudo cat at c password, it I don't have to enter my password now. But if I do sudo -k, it resets that timer, and now it's going to prompt me for my password.
-
So So is an important um an important one that you can that if you run sudo it's going to set a timer basically Now when we were adding the test user the let's let's do another test so so let me show you how you can search your history if you press control r and then add user we get the previous command here that's with add user so we're going to rerun the command add user test user okay so we now have the test user uh again If I then um want to switch to that user you can use the sudo su switch user and then test user and now I am test user who am I test user I'm now test user Now [snorts] if I want to run let's say I just created test user and test user is now thinking feeling a bit frisky and thinking yeah I'm going to do some uh admin sudo commands here so sudo cat etc password If I do the password for test user then we see that test user is not in the sudoers file
-
In other words he is not allowed to run uh sudo commands So the rules you will see here the rules are defined in etc sudoers and you should not edit this directly use v sudo but let's see if I um if I go to the sudo cat etc sudoers file this shows the configuration of the the the sudoers so here we see that members of the admin group may get root root privileges or allow members of the group sudo to execute any command. Here's what's configured. So, if I do groups here, we see that my user is member of the sudo, but if I do groups test user, we see that the test user is only a member of the group users.
-
Test user and users. Cat etc groups or etc password. Test user is his own user here with the ID 1004 and the only member he is a member of the only groups that he is a member of is test user and users. So, again, check out the man groups command and if we do groups option username, so prints the group membership memberships of each username. If no username is specified, it will or for the current process if it's if you don't specify. So, again, groups test user. Test user is a member of these of these users. Now, let's add him to the sudoers group because again, sudo cat etc password, he cannot do it.
-
If we then do sudo user mod a g sudo test user. If we now do groups test user, we see that he is now a member of the sudo group, right? Now, if I run this again, it's probably not going to work. Yes, because this is not loaded while the user is still logged in. So, if I exit, I'm now back to the normal user because remember we ran this sudo su test user command and essentially what this does it this creates a new shell for that user, right? So let's do that again. And now it's actually telling us to run a command as administrator, use the sudo command. It's actually already telling us that we can do it. But if we now do the sudo cat etc password and pass, we're allowed to do it right?
-
So that that is how we can manage the permissions of the a certain user. Let's exit again. And we can uh remove that user again. So now he's removed again. And if I do groups test user, it says no such user. So now we are the only administrator again. And that's how it works. So we've covered a lot in this lesson, but it's very important to grasp this properly, especially when you're going to run um containers. So uh I am I have a little challenge for you. Go through it and then there's the hints down below that will solve you how to solve show you how to solve them. And when you're done with that, I'll see you in the next module. Welcome to module eight where we're going to be learning about input, output, and pipes. So we're going to be answering the following questions. What is standard in, standard out, and standard error, file descriptors, saving command output to a file, and piping. So this is going to be an interesting lesson.
-
Every program has three standard streams, what is called a stream. So you have input, you have output, and error. So yeah, this is a bit um theoretical. So we have to just get you have to see it in order to understand it right? So if I cat something, cat, then it's going to read from standard in and write to standard out. So if I cat hello here, it's just going to put it back. So we have been using cat as a way of showing files, but cat itself is also a command that can be run. And when you run it, it listens for standard in. So, what I'm typing now is standard in. And then it's point and it's writing it to standard out. So, if I press control D now, so cat implements standard in standard out in this sense.
-
But if I went if I now um do LS non-existent, it says non cannot stat this because there's no such file or directory. Now, they are both on my screen here, but this is in fact an error. This is not standard out. This is actually standard error. So, the input of a command, so cat if I do cat Etsy password. And if I then pipe that to um WCL, then we're counting the line numbers, right? Where we we um learn about this. The standard input of the WCL command in this case is the output of that command. So, cat Etsy password has this as output, which is standard out.
-
Standard out. And it takes that and gives that to the standard input of WCL. So, I find it easier to just remove the word standard here. So, if you just remove the word standard, each command can just have an input, an output, and an error. But we call it standard error because of convention. But that's simple to think about it. Any command has a input, or not all commands have input, but um if you run a command, it can have an input, an output, and an error. So cat etcpasswd has an output. We give that as an input to WCL, and that in turn has a standard output of 32. But if I do something like LS non-existent or assistant or whatever, it's going to show it to the screen, but this is in fact not standard out. This is this is standard error.
-
So we're going to be seeing how this works exactly. So we because we have this output, we can redirect this output. We can take the output of one command and put it somewhere. So if I do LS etc C and then I write this symbol and put that in listing dot txt, then if I now cat this, we see that listing dot txt has the output of the command LS etc. Right? If I do LS etc, we see this. So this is stored in this text file. We can open the listing dot txt and and edit it. We can we can now work with this if we want to. So we can redirect the output of a command into a file. Yeah, if I'm I will just going I'm just going to remove all of these files here. Test dot txt and test two txt. Okay?
-
Yes. Okay. Everything is removed now. Now let's echo Again, this is where echo like we we thought echo was a bit of a silly command, right? Because echo you just you just print something to the screen. Well, this is where echo becomes useful because we can echo something and put it into a file. If I now cat file the txt, it is line one. This is equivalent of let's say I want to do VI my file and then line one. And exit this. Cat my file has the same content as file.txt, but I could I put this text in there by just running a command instead of having to open it in an editor. Now you've seen this command this symbol for redirection, the greater than symbol. If I use two of these, it's actually going to append this because this is going to replace the content of the file.
-
So if I do echo line two, and now cat file.txt, we see that it is there. If I would then if I let's say I would do echo line three, and I do only one of these file.txt, guess what's going to going to happen. If I cat it now, it has replaced the content of that file with just line three. So you have to be very careful if you have a file with content in it and you want to append it, so you want to add add it to the bottom of the file, then you use these two greater than symbols. If you don't do it, then it's going to just replace the content of the file with the output of this command. We can also redirect input. So earlier I was doing cat etc password and and piping that to W C L.
-
We can also do W C L and then take etc password as the input of that command. They are exactly the same. Now let's do the let's now check out the errors, right? Because we saw that we can also get errors. So if I do this command LS non-existent to errors.txt, if I do cat errors.txt, now see that it is there. Right? That's what we were um um expecting. But we can also redirect both standard out and standard error. So if we do the same command, all output, now we get LS we are doing LS at C and LS non-existent and then we use the N and greater than command and it gives us all output because we see here we have both cannot access non-existent and the output of the LS at C command.
-
So if I were to run the same command, so let's remove the all output command here at the file. If I do the same but I just redirect the uh um if I if I don't add the N symbol, then we see that it is it is going to output this. But if I now open this file or cat it all output, then we see that the line where it says the non-existent is not added to this file. Do you see the difference there? Let's do that one more time because maybe this went a little bit too fast. Okay. So I'm going to make the screen a bit bigger. I'm going to remove the all output file. Okay? I'm going to run the command LS at C and non-existent. So what this is going to do is is going to LS the direct the content of the at C directory and a directory called non-existent, which is non-existent.
-
It cannot access it because it doesn't exist right? So this command is going to do to show the output of LS at C and LS non-existent, but it cannot see this because there's no file directory and then it shows me the output of the same if I would do LS at C, right? Now if I want to capture because here we see it it does output this line here. It shows me, hey this this directory does not exist. Now if I were to take that command and I want to put that in all output .txt, we see that it is it is showing me this in the terminal, right? So but it it we are we would expect that if we do cat all output .txt that this would be in here, but it's not. Do you see? It is not here. It only shows the at C and the list of those of that directory.
-
So if I also want to capture the errors of this, then we have to add this symbol uh the ampersand. So redirect both standard out and standard error. If I want to take both of them, I have to add the ampersand to this command. And if I now cat the all output .txt and scroll up, we see that this the standard error, so the error that this command produced is now also included in that file. So I hope that is that is cleared now. Let's say we want to take the the output of LS at C non-existent and store the output of standard out in a file, but the standard error in a separate file, we can do it like this.
-
So we take we run this command and the standard out we're putting in standard out .txt, standard error is going to standard error txt. And lo and behold, if I cat those, cat standard out here, this contains this. And if I do cat standard error txt, it's showing me the error that we were redirecting. So this is the standard out and this is the standard error. We can also discard output. So if I do ls at c and put that to dev null, it's not going to do anything. It's outputting it to dev null. So this is a black hole and this is this can be useful for um doing it in for this can be useful in scripts etc. You can and this is how also how you can hide error messages, right? So if we do ls non-existent, it it's now showing no no such file or directory exists. So if I then take the two and pipe that redirect that to dev null, I'm running the same command, but it's not showing it to me anymore because I'm taking standard error and I'm pushing that to dev null.
-
I'm redirecting that to dev null. And all of this becomes very important when you start writing scripts later. So those are standard in, standard out and standard error. And now let's take a look at the pipe operator because what I've been doing constantly is scrolling up in the terminal and that is actually really um inconvenient. So fortunately we have commands to help us with this. So again, if I do ls at c, but then I give that output to another command, in this case head, which is going to take that input and then it's going to output the first five lines of this. Isn't that nice? So instead of constantly doing cat all output, I could now just do head and five and uh give that the all output file. And now it's going to just head that, right? It's going to give me the first lines of that, so I don't have to scroll up anymore.
-
Again, head N five all output and it's just showing me the first five lines. Now these pipes are can become very powerful because I can do cat etc password. Let's do this one by one. So cat etc password. This is the contents of the entire file, right? If I now want to filter out all of the uh lines that have bash in them, I can pipe that to grep bash. Let's do it clean. Cat etc password and pipe that to grep bash. And again, this is not good teaching. You should not just cat something and then grab it because we know now that we can just run grep bash etc password. And there's there's the same output, but I'm just demonstrating the piping here. So cat etc password and grep bash. So we're taking the output of cat etc password.
-
We are piping that with the pipe symbol to grep bash. So it takes the in the output of the cat command, takes it as input, processes it and then gives some output. And then we can pipe that to WCL because we want to count the numbers. We want to count the number of users that have bash in the shell. And now we see that there is two. If I again do an add user and test user here. If I now run the same command, we see now that there's three users with the bash shell in it. So this is extremely extremely powerful piping things and um using these as filters because that's what these type commands are. These are called Unix filters, Unix filters.
-
And in the bash scripting course, we're going to go even deeper into this and we're going to be writing our own Unix filters that we can then use in Vim for example. So here are some practical examples of this. So for example, the history command, it outputs all of the history. Well let's let's see if I want to see how many times I have typed the word bash in my history, right? So if I do the history command and then grab that for bash, now I see all of the times that I've written bash in my history. If I want to count that, I just do WCL and boom, I see I've I've written that 10 times. If I want to see how many times I have written grep, we see that we have written grep 31 times. If we want to sort who is logged in, we can do who and pipe that to sort.
-
This actually does that automatically already, but you get the idea. Sort is a command we're going to look into in a second. If we want to count the files in a directory, so LS at C and then WCL, we now see that there's 202 files in this directory. That's useful information. Let's find large log files. So DUH var log star. This shows us a list of directories. Then we can pipe that to the sort command and pass it the H flag. And now this has sorted the output of DF-H var log in a human readable format. Do you see that? So let's out the difference here. Maybe it's better if I do it in a bigger one. So du sh Remember what that command does? It shows you the disk usage of that directory. So var log and then star.
-
We haven't learned about the star yet, but that this means take everything in this directory and and scan it. So now it's showing um in human readable format. Yes, it's now showing the size of the files in the var log directory, right? But this is a little bit annoying because it's not sorted nicely because 4k 39 hm So let's say I want to sort this it because this is just a mess. If I clean it up and do this and then pipe that to sort dash h, so sort it for a human then it's showing me the neatly that the var log journal is 39 megabytes and then it's going to just descend it like this and then the smallest files are var log read me etc. So the biggest file is at the bottom and the other one is at the top.
-
Another one is searching for running processes, which is very useful. We're going to learn more about that in the next lesson, but if I do ps aux now we see that there's a ton of things running here on my system. But let's say I want to filter out the polkit uh process. So we're going to learn about ps aux in the next one, but ps aux grep polkit and now we see only the processes that have polkit in it. And notice that the grep process is actually also um shown here. So these are filter commands and these are designed to work in pipelines. So let's create some files to work with. Um, I'm going to remove all of these text files, and I'm going to show you a little trick because we saw the star. But if I do remove star.txt like this, LS, now we see that we have removed all the text files from this directory. I'm going to remove my file and keep everything nice and clean.
-
So I I can run a a few commands after one after another. So I'm just copy pasting this and copying and pasting this. And if I do cat names.txt, now I see that because we were appending lines, right? There's now a file with Charlie, Alice, Bob, Alice, Bob, Charlie in it. So let's see what we can do with this. First we can do sort names.txt. Now it has sorted it. So if I do cat names.txt, this is the actual contents of the file. But if I sort this file, it's sorting it alphabetically. Right? If I want to reverse sort this, clear, uh, sort r names.txt, it now starts with Charlie and Bob and Alice. We saw already saw seen this one, the du var log, and for good for good measure we are redirecting errors.
-
So actually that that's a good one to show because if I did the du command here, we see that it is showing the cannot read directory var log private, right? It is actually including that in the output. But if I now do it like this, oops. Here, we now see that the output does not include that. So we redirected that error to dev null. So that's an interesting use case of it. Sort is a useful command, but what's even more useful is unique. So let's remove the duplicates. We can uh sort names txt. So, that's going to give us this. But if we pipe that to unique, it's actually going to remove the duplicates from that output. So, you see maybe you can already see how this becomes useful, right? Instead of having to write scripts, we can actually run a series of filters because let's say I get the job of a file which is has hundreds of names in it for some reason.
-
If we then want to get the unique names, so I let's say these are all the same persons, but for some reason they were added double to it. I can just take the output of names txt. It doesn't have to be sort. It can just be cat names txt. And then pipe that to unique. Now I only get Oops. Oh, interesting. I actually didn't know that. So, apparently I need to sort it first. Sort names txt and then do unique and then I get the the the duplicates. That was interesting. So, it needs to show it needs to sort it before it can detect the uniques. We can also count the the occurrences. So, we have three Alices, two Bobs, and one Charlie in this file. So, again cat names txt. Let's say my boss gives me a huge file and he says, yeah, there's all these duplicate names in there. Figure it out. Okay, so instead of having to write a program or God forbid having to go in there manually, we can just do sort names txt and then pipe that to unique c.
-
And then we see, oh, there's three Alices, two Bobs, and one Charlie in my file. Pretty neat, right? And you can create huge pipelines with these filter commands, pulling out the information you need, manipulating it, and then getting the output that you want. So, one of these commands is the cut command. So if I do cut D F1 at C password, let's unpack that a little bit. So you extract field one using the colon as a delimiter. So that's what the D colon means. If I open up the cat at C password file, if I print that, we see that it has bin colon X colon two colon etc. So the delimiter here is the colon. The colon is the separator of these columns, you could say. If I cut it by the delimiter D, then it's going to split it up by that delimiter.
-
And if I then give F1, it's going to get me the first field. And in this case, the first field of this file is games man etc. It's the username. So if I want to print out all of the usernames in at C password, I can do this. If I want to get fields one and three, I run it like this and now I get the user and their ID, right? You can also cut characters. So if I do echo hello world and cut character one to five, all I get is hello. And you can translate characters. So if I do echo hello in capitals, and if I translate A to Z in capitals to A to Z, is now putting them in lowercase. Pretty cool, right? If we do echo hello world and replace spaces with new line characters, it's going to put hello world in on the separate line.
-
This means put it this means a new line character. And we're going to be learning more about this in the bash course as well. Here if I echo 1 2 3 and if I then translate that and delete the zero to nine, so I'm deleting the character the numeric characters from this, what I get back is a b c. So you can see how this can be very useful when you need to take a ton of output and then manipulate it. So let's say I want to uh remove all the user IDs from a file. Well, you just do t r d and remove all the numbers and then all the numbers are removed. These are the concepts of Unix filters. T is a useful command because this actually um writes to the screen and to a file at the same time. So what we see is it has printed to the the the console, but if I do cat listing txt, it is actually showing me the content of the file. So it printed to the console and it uh printed in it wrote to the file because if I do ls at c and put that in listing txt, it doesn't show me anything, right? So that is the difference between doing this and using the t command. So the xargs command is also very useful. Let's see if we cat names txt and run it through xargs. It is now going to write
-
hello and then take these um each each line of that file and as input to the echo hello command. But if we want to process one at a time, we do xargs and one and what we see then is it's going to say hello Charlie, hello Alice, hello Bob, etc. This can also be very useful to do one argument per command. So this this the the file the the the file containing names, each of these can become an argument to a command. So if I do echo Alice, echo is the command and Alice is the arguments to that command. It's the the input. Of it. Now what xargs does is if I cat this file it sees oh there is five or six lines in here.
-
And for each of these I'm going to run the the the command that you specify. So n one it it goes if I for example I can also do if I do n two here then it's going to say hello hello Charlie Alice, hello Bob Alice and hello Bob Alice. But if I do n one it's going to do that one at a time. So this is the command that we are going to execute with one argument at a time from this file. And here if we do the let's say I want to create a file for each of these names. So if I do sort names txt pipe that through unique. So I want to only create the files I only want to create files for individual users. And then I'm going to touch the I'm going to touch a file for each of those.
-
If I now do ls we see that we have Alice, Bob and Charlie. Right? Pretty cool. So this was the lesson about redirection. We've learned about the greater than that we can redirect. This appends it. We have learned about standard error and standard out. The sort command, the unique command, the cut command and the translate command and even the xargs. Now we have just scratched the surface of xargs but xargs is actually an extremely useful command to know as well. So here's a little challenge for you. Create a pipeline that analyzes etc password. Let's extract just the usernames, sort them alphabetically and count how many there are. And save the sorted list to users txt and show it on the screen. This is a fun little challenge for you. So go ahead and do that and then I'll see you in the next module. You've just learned one of the most powerful things in Linux, combining commands to solve problems. Put it into practice before moving on. The workbook has all the exercises where you work with pipes, redirect output, and build your own command pipelines. Solve them yourself first and then compare with the solutions. It's all for free inside the Linux community. The first link is in description and now let's move on.
-
Welcome to lesson nine where we're going to be learning about processes, understand what's running in our system, how to manage them, and how to control them. So everything, every running program on a Linux system is a process and understanding processes is essential for troubleshooting and system administration. So questions we'll answer is what is a process? How do I see what's running on my system? How do I stop these? And we're going to learn about systemd. So let's dive into it. What is a process? A process is a running instance of a program. So when you run LS, a process starts, it does its work and then it exits. Long running programs like web servers stay running as processes. So our SSH session into our server here is a long running process and we're going to be looking at that so in a second. So every process has a PID, a process ID, a parent process, so a process that started it, an owner, and a state. So it can be running, sleeping, or stopped, etc.
-
And to list our processes, we use the PS command. These are the current our our current processes that we are currently running. Now for me, when I'm running this, it's the bash process because I am only running the bash process here. And as I am running the PS command, I'm also running the PS process. So it's the processes that are attached to my terminal. If I want to see all processes, I run the PS aux command. aux. This shows all the running processes on my system. And remember we we also saw this when we did htop, right? Here we also see a bunch of processes that are running on my system. So the flags mean uh a, it means all users. Then u is user oriented format. And x includes the processes without a terminal. Because if I just do ps aux, then the the there's only it's only going to show me the processes that are running in a terminal. But aux, it actually shows all of the background processes that are running separate from the terminal. Because there are more processes that are required to run for me for this system to be operational, right?
-
So in the field, in in your daily work as a as a engineer, ps aux is what you use most. ps aux. That is the default one to learn. ps aux. Burn that in your brain. Now we can also search for processes by simply using grep, right? And piping that we have learned. So ps aux grep cron. Now we see that there is one process running here. User has been cron. But note that this grep process is also included here. So this is not running anymore now because the grep process has finished. But always remember that you will see this grep here. That is because we capture it while you are running the grep command. So that's important to note. So you can take the output and uh pipe it to grep. But there's also the pgrep command. pgrep cron does the same thing, but it only shows us the process ID here.
-
And the process ID here is what you see here, right? This is the PID that we saw. And the owner of this process is root. And the ID is that. But it just returns the PID. Now top is an is the interactive process viewer. So we were running htop like this, which is a fancy version of top. This is the old school version. This is the interactive process viewer. And here there are a few commands that we can do. We can quit and we can kill a process. So let's see if we do which process can we kill. K and then yeah, it's going to show me PID to signal kill. And the PID of the top command here is this one. So if I run Q and I enter the PID, so it's showing me the default or is this one. If I press enter now it should actually kill that process. And yes, it has now killed it because look, I can now type.
-
So I'm not in that process anymore. So let's do it again. If I do top and if I do Q to exit it, if I do top again you can see that I cannot type here, right? But if I do K in this case it's going to suggest I kill the top command here because that's the only user process that's currently running that would be a candidate for this. So I'm going to accept the default. I'm going to accept this sigterm default. We're going to learn about that in the next section. But now it has successfully killed that process. Right? Again top. If I now go here and if I do p grep top, we see that the PID of the top process that's running here. There. If I do PS aux grep top, then we see that the the top command that is running here has this PID and if I do K, it's going to tell me to quit that.
-
We can also sort by CPU, so capital P shows me the processes that are running the most CPU. Ironically, top is now using the most CPU. If I press capital M, we see that snapd is currently running taking the most memory. And H for help. So it's going to show us the help. But top is available almost anywhere, but very often you are going to be using htop or an even cooler one is btop. So let's even let's just review installing our our system. So what I want you to do now is to update your package repositories, then install the command btop. Do that now. I'm going to give you a second that you can pause the video and if you are done, I'm going to show you the solution. So sudo apt update. We are now updating our package repositories and this is now done. And now if I do sudo apt install btop, it is now installed. If I run btop, then we get an even fancier one. Wow, look at this. This is pretty cool, right?
-
It's showing us all sorts of things. It's now showing us the the CPU cores and what they're using. It is showing us the disks. So it's showing that I have used 5 GB on my system right now. The usage of the firmware. It's showing me my networking stats and here are all of the processes. And if you can check out the menu for some help, navigate with the options key. This is a very cool process or a very cool process manager to run as well. We've already installed htop and that's how you can use it. So press control C in a terminal to stop the the current process. So if we run top the the standard way to do this is to press Q. So now top is not running anymore. But if I run top and I press control C, it will also stop running, right? You see I can type it now in the bottom. So control C is the universal way of stopping a process.
-
Now let's learn how to kill a process to from the command line. So in this terminal I'm going to be running top and here and you haven't learned about tmux yet, so you're going to be learning how to do this. But what you can do is you can just open a new terminal. So Alacritty like this. I just open up a new terminal. In West Term you can just open up a new pane and then you can SSH to your machine, right? So you can do it that way. I am just using a using tmux that we're going to be learning about. So I have a process called top that's running now. So if I do p grep top, we have the the ID of that process, p grep top. So this is the ID of the process that's running right here. Now if I want to kill that, I can do kill 32 830 and this is going to kill the process.
-
And now here I see yes, it has in fact been killed. So this sends a SIGTERM, a polite request to stop so the process can clean itself up. There are several signals that you can send. This one has the number 15 but there's also the SIGKILL command a signal and this will force the the process to be killed. So use this when the process ignores the sigterm, the normal kill, because this is usually like sometimes a process gets stuck, it won't listen, then you do kill -9 and then it will kill it. You can also kill by name. So if you run kill all Firefox, it's going to kill all the processes named Firefox. In this case, if I run the top command again, and if I do kill all top, then we see here that it has successfully killed it.
-
And we can verify that by doing pgrep top, there are no processes running pgrep running top anymore. We can also put commands in the background, and you you can do that with the ampersand command. So sleep is another command we can learn. Sleep five is simply sleeps for five seconds and then it exits. This is useful in scripts when you are doing sequences of commands. If I do the sleep 60, so this is going to sleep for 60 seconds, and if I do the ampersand here, it's now putting that to the background. And if I run the jobs command, I can see that the sleep command is now running in the background. If I now run the jobs command, it is still running, but in 60 seconds from now it will be finished. So if I were were to run the sleep command for 10 minutes, if I now do jobs, we see that the sleep 600 is still running.
-
And this one, the job is has the ID of two. So if I want to bring that again to the foreground, you do fg percent two, and now sleep 100 is back to the foreground again. So it is now running in my interactive session and not in the background. So if I want to suspend this now, because I'm now in this process, I can do control Z. And now it is um it's now stopped. So jobs it is stopped. And if I do BG, it is now continuing again in the background. So jobs we see that the this job is now done, but it is now uh I suspended it earlier. We stopped it. And then when I ran BG, it then kept continuing. Now this is not something that you use very much, but I do want to I you do need to have seen it once that you can run a command, sleep 500 and with the ampersand you put it to the background. And if you run the jobs command, you can see all of your background jobs.
-
Now let's learn how to get some information about our system. We've already done the cat Etsy OS release. So here you can find information about your OS. But if you run Uname A, you actually get information about your kernel. We've actually seen that earlier as well. So we are now seeing that we are running kernel version 6.8.0. If I were to run this on my host system and we see that I'm running 6.17. And that is because I am running cat Etsy OS release. On this particular system, I'm running Fedora Linux. But I'm just testing it out. I usually run Arch Linux. But here you see that Fedora is using a higher version of the kernel than the Ubuntu Server LTS version. And that is what I meant with when selecting the server, then this one has not all of the latest fancy updates, but it is more stable.
-
Let's check how long this this command this system has been running now. So it has now been running one day. We can also see how much you memory we are using right now. So free dash h. This shows us how many how much memory we have. My Raspberry Pi has 4 GB of RAM and we are using 304 MB. I mean how cool is that? We have this full operating system that we've been practicing so much with. We've been learning so much on just the small Raspberry Pi. And this Ubuntu server is only running 300 MB. Like I I just absolutely love that. Try checking that on your running Windows machine and see how much it it's using. It's like 8 GB or something. Let's get some information about the CPU. So LS CPU. This is going to output all of the information of our about our CPU.
-
And if we then grep that, we can do the now we just see the how many CPUs we have and the name and the the scaling megahertz for example. Just the essentials. We have seen the LSBLK command earlier, but now is a good way time to do it. So LSBLK, it shows you the block devices, which is another name for disks. And in this case, my system has a few loopback devices and you're going to be learning about that in in the future. But this is the main disk because I see that because this has 60 GB, right? And my disk has a couple of partitions, part boot firmware and in the root partition. Now this may be a little bit cryptic to you but if you want to learn more about this, this is what I do in the the Arch Linux course in CubeCraft.
-
There is a course that is going to teach you how to build an Arch Linux system from scratch. And this is also where you're going to be partitioning the disks. You're completely yourself. So this is going to teach you how to work with logical volumes, how to create partitions and how to actually get really deep into what this is and how this works. So if you want to get deeper into this, I highly recommend you join Cube Craft and do the Arch Linux course and then you will know exactly how all of this stuff works. We've also seen the DF-H command already. DF-H. This shows you the current usage of the entire system. So my main block device that we saw is is has 53 GB available and has 5% in use. Next we're going to learn about system D. So system D is the monitored init system on Linux.
-
So remember when we said that each process each process has a a user and a PID, but it also has a parent ID, right? Each process has a parent. Now you can now I'm going to teach you about the command PS3. Here this is these are all the processes that are currently running on our system. If I now run the top command in this one PS3 now we will see that top has appeared here. So this will show you the the the process tree of the entire system. In this case the system D is the parent process. This is the init process. This is where everything starts from. So when you boot your system you have something that's called the BIOS that's going to load the Linux kernel. The Linux kernel then starts the init process, which is system D and from system D, everything else spawns. This is the tree.
-
So here we see that I started a process called SSHD. This is the SSH SSH server. This has started a bash shell. And in there, I'm actually you're still seeing the sleep command being run, right? Those are if I do um jobs. Is that still jobs? Yes, this user session still has a couple of um jobs running. So we can see that actually in the PS3 here, there's two processes with sleep that are still running. And it's running top. So the PS3 shows you all of the processes that are running currently on the system with their parents. And this is how you can visualize them nicely. Now in the PS3, we see that system D starts is the the parent process of everything. So it's the init system on modern Linux.
-
It starts all the services at boot. It manages the running services. It handles the dependencies between the services and it collects logs. So system D is basically the puppet master of the system that basically handles everything. And if you want to get into the history of this, so you you have you had something called sys V in it. And we're not going to go into the details of this, but you should know that at one point sys V init or sys 5 init was the main init process. So when you ran init um if you ran PS3, then you would see the init process was called init, I believe. But later, this was replaced with system D and this was slightly controversial and there are still people what was it? System D kill or something. Um well I I don't forget now, but there is like a a website that is this whole um manifest against using system D. So, people are still doing heated debates about this, but all you need to know is that all modern systems use system D and this is what you'll be using at work.
-
So, when you want to interact with system components of your system, you use system D. In this case, uh let's check out the status of SSH. So, what this does is you run system CTL, system control. System CTL is then the command that is going to allow you to interact with all these system services. In this case, we are checking the status of the SSH service. So, everything is running as services. And it shows us information how it is triggered, the documentation about it, the main PID, how many tasks it has, how much memory, but also more importantly, the logs of that process. So, what's going on with it. And it's so it's showing you that hey it accepted a new process here at um uh a connection from my main system, right?
-
Um you can also start and stop these services. So, if I do system sudo system CTL status cron, we see that the cron service is now running. It's running some regular background uh background processes. This is now actually running. Now, if I do system CTL sudo system CTL stop cron. And then if I run the status again, we now see that it is actually stopped. So, you see the the um the symbol here changed. It is loaded, but it is now inactive, dead, right? It is stopped. And in the logs it's saying stopping cron service. If I want to restart it again, so sudo systemctl restart cron. If I now do the status command, it is now restarted again.
-
See? Started cron service regular about. So this is how you can start and stop these services. Now cron is enabled. You can see it here. It's enabled and the preset is enabled. If I want to this means that it's going to start when I boot up my computer because we never changed this. This was running while we were um how we by default this was running. Now if I do system sudo system CTL disable cron, we will now if we now check the status of this, we see that the it is actually disabled. And if I now were to reboot my system, then cron would not be running. Cron would actually um actually we can just do that. So sudo reboot. I'm going to reboot my my Raspberry Pi now. So we see that this has now been um um closed. Actually did we cover reboot yet? I don't I think we haven't.
-
So now you know how to reboot your system. You just do sudo reboot. Another a better cleaner way is to actually do systemctl reboot. But my Raspberry Pi is now rebooting and it might take a few seconds for it to come back up. So let's test if we can SSH. Now it's not connecting yet. Oh, now it is. So okay, we have successfully rebooted. If I now do sudo systemctl status cron, we see that cron is not running because it was disabled, right? So we have to sudo systemctl enable cron. It is now enabled again, and sudo system ctl restart cron. And now if I do status cron, we see that cron is running again and it is enabled, so it will be restarted when I am rebooting my system. If we want to list all of our services, we can run this systemctl list, and this is going to run list all of the running services. So as you can see, there's quite a few services that need to be running for a system to be to be running for it to be fully operational.
-
But this is how you can then you can see the services, but you will very on Linux servers, if you are running a process, it's very often going to be configured as a systemd service. So this is why it's important to know how to start and stop services and check the status again of them. So sudo systemctl status, if I want to check out what's going on with my SSH server, you will do that with SSH with systemctl status SSH. The next command, this is also this is journalctl. So journalctl is the command to view system logs but through systemd. So you can do cat var log syslog like we did before. This is the actual log file. But if you do journalctl, you can now it it opens up a pager for you, and this is the this is the best way to do it basically. Here we see that this in the log we can see that cron was started and that we are running some it's logging that we are running some commands as user, right?
-
So we are from the the directory home user, so that was me. As the user user, we actually ran the command user bin system ctl status ssh. So it's logging that we were running these commands. If I want to check the logs for a specific service, you can do sudo system ctl u ssh. So it's going to give the logs of the user service ssh. And now it's going to show me all of the logs that we have gathered from the ssh. And again, this is the same. So if I do shift g, it's going to go to the bottom. If I do gg, going to go to the top. And j and k is how I can go up and down in this. If I want to exit this, I press q. If I want to follow the logs in real time, I can do let's open up a new session here.
-
Remember the old command that we ran for this? It was called tail f. So this was tail f was logging the sys log like this. But there's also the journal ctl f command. And this also shows logs. So if I now go here and I sudo do sudo system ctl status, this should now log exactly that I have ran this command as root system ctl status. So you can follow the system logs like this while you are doing some commands. Another one, very useful one is if I want to check the logs of one since one hour, you just run this command and then it just shows you the logs from the past hour. This can be very useful because since one hour ago because when you're running your system and you're running it for days, weeks on end without rebooting, this log file gets huge, right? And if you just want to check the the from the past hour or the past days, you can just filter it out like this. And journal CTL B because by default journal CTL contains logs from all of the boots, but if just journal CTL - B, it's actually showing the logs of only the current boot.
-
So let me see can I demonstrate this? So here this um journal CTL - B command, if I open that the first line here is oops is December 14th. So that's the current boot because we have just rebooted. But if I just run journal CTL, then we see that the first line is actually December 13th, right? So it includes logs from previous boots. And that can be a little bit um unwieldy if you are if you're just interested in what's going on in your current session, your current boot, you just do - B. And then it only shows me the logs of my current boot. All right, so these have been some very very useful and important commands. So we run now we know how what processes are, how to view them, how to kill them. We know how to do jobs on in the background.
-
We know how to get information about our system and also how to view our logs and to interact with system CTL. And again, this is just scratching the service, but this is enough to get you on your way. If you want to go deeper into system CTL, I I built my whole Arch Linux course around system CTL. And the interesting thing is that system CTL can do many things that other people are using with separate programs, right? So for example, um there is a program called let's Google it NMCLI. NMCLI is the is the network manager. So, NMCLI is the maybe it's even on the system. Which NMCLI? No, it's not. So, network manager is a program to manage your networks and you talk to the program through NMCLI.
-
Well, a lot of this can actually be done through systemd, like configuring your networking, configuring DNS resolving, etc. All of that can be done through systemd and you don't need network manager. So, I have this philosophy when building my own systems that I would say that if you can do it with systemd, do it with systemd. Try to keep the amount of programs you are installing as minimum as possible because if your system comes with these things out of the box, your system is already able to do network management through systemd, then what you should do is you just use systemd for that instead of installing a separate program. And all of that I teach in depth in my Arch Linux course. So, when you go and and do that as the next one, then you're going to be learning more about PS3. So, we're going to take our system from absolute zero and build it up and then we're constantly going to be analyzing each and every process that I that is being put on the system so that by the end of the course you have the exact understanding of each process that's running on your system and why it's there and how it is configured.
-
And also everything is going to be done through systemd. So, if you want a true deep dive, then this would be the next step for you. Now, that being said, there's a little bit of a challenge here for you. Find out how many processes are running. So, you're going to be doing some piping here right? Find the process using the most memory. Check if SSH service is running and when it was last booted and see how much memory is available. So, take on that challenge and I'll see you in the next module. In this module we're going to be learning about networking and SSH. So, a few networking basics and going a lot deeper into SSH. So, this is not a full networking primer. That's beyond the scope of this course, but I am going to teach you enough to get enough you need to know to manage your Linux server from the command line. So first let's check out how we can view our IP addresses, right? And we've already done this in the beginning when I showed you how to SSH into your server, but if you do the IP addr command or IPA for short, this is going to show the network interfaces on your machine.
-
So, your your your machine contains several interfaces like network cards or in this case a wireless connection. So, my Raspberry Pi has a wireless network interface which has a state of down because it's not activated, but there's also an Ethernet interface which is up. We state up and then the inet here shows the IP address and that's the one that I've been using, right? Now you will also see that there is a loopback device here, loopback. And this has always has the same IP address, 127001. And this is you may have know you have come across this already. This is known as localhost. So, you will you will when you're doing when we're going to be learning about Docker containers, we're going to be connecting to localhost and port forwarding to localhost. This basically means connecting to yourself.
-
So, you can I believe you can actually if I do SSH user at I can actually SSH into my own server. And this is then like this. So this is I am now SSHed from my server into my own server. You can actually do that. Because now if I do W, I will see that we have three users logged in. And one of them the source IP of one of them is 127001. So I'm SSHed into from localhost. So that was a bit of a funny demonstration. But in short, you can check your IP address from here and the L the loopback interface is known as localhost. Next, we can run the IP route command.
-
So this is going to show the route that your IP address your your requests make. So IP route in this case it goes via 168100.1 which is the IP address of my router. So IP route shows if you're and if you are on a cloud server, this will show multiple steps where it goes through many different types of routers and interfaces, etc. But my network is very simple. It just goes through my router and that's it. The default here is your gateway. So where where your traffic goes to reach the internet. And in my case, that is the router. Now we can also check the hostname of our server. And you can also do that with hostname CTL. And with hostname CTL, you can also change your hostname if you wanted to.
-
So your hostname is the name of your of your server on your network. The Etsy hosts file that is also an interesting file. This contains here your system has configured manage etcetera hosts as true, so if you if you want to change these and have them persist, in this case we have to change them elsewhere, but this file basically contains um address um information about addresses and you can set aliases from for them. So here we see that my um the host Kato is actually uh attached to local to a 1.1. And here the loopback device is alias to localhost. So if I do I could actually do the SSH user at localhost and then it would work as well, you see? So localhost is then an alias for that IP address and you do that in the etcetera hosts file.
-
So if I were to oops if I were to change this um so I'm now opening a new terminal on my my host system, so I'm not on my Raspberry Pi. I am now on my main Fedora system. If I do sudo vi etcetera hosts, then here this is my um uh my hosts file. If I then add in this case let me call that um hello um Julius right now, so like this. If I now do SSH user at Julius, it actually will it's able to know to route to that, right? Because you see it it is going to throw a bit of errors because I'm already SSH into it and it has a few other known hostnames, but uh I can actually SSH now because my hosts file is saying Julius lives at this Let's see hosts.
-
If you want to go to Julius, you can go here. See? And actually I already have a server called Julius and that's why it's complaining. But this is how it works. So as um instead of typing the IP address, I can just use Julius. Now I'm going to remove that from the hosts file again. Like that. So now it's removed. But that is how you can um can you can set up you know aliases for your IP addresses if you have multiple servers and then you don't have to type the IP address all the time. A few interesting network tools. Ping is for testing network connectivity. So if you ping google.com it's going to send a ping request to google.com and the google.com is then going to respond and you press control C to stop this. If you just want to do that four times, you can do ping -c 4 and then it's just going to do it four times.
-
Now it stops, you see? And shows you some statistics about it. And another very useful command is curl. You're going to be using this a lot in your career. So curl this basically sends a request to example.com and then it's going to pull in the raw HTML code of that page. And it shows this domain is in use for documentation examples without needing permission. If I go to example.com like this then this is what you see, right? example.com. So you can pull the the actual contents of the webpage with curl on the CLI. Then you can also download files from the CLI. So if I yes, I already have a um markdown file. So let's just clean up a bit here. I'm going to remove all the txt files and md files. Now we have I'm going to remove Alice, Bob, and Charlie, and readme.md. And you may see me completing like this. I do that by pressing tab, the tab key. So if I do r e and tab, then it's going to show me, oh, you have some you probably mean this.
-
So the tab key is also one to get used to as soon as possible. So now my directory is clean again. Now if I do curl - o and then I give it a URL. In this case, it's a readme file in one of my GitHub repos. If I now ls, I see a readme file. And if I cat that, I see the contents of that readme file. And it's a the contents of the readme file in my lab repo. Now if I want to curl into my own custom file name, I do curl - small o, curl o, myfile.md and then the same URL. So - o uses the remote file name and this - capital o and then the non-capitalized o, it puts it into myfile.md. If I cat that, then I see the content is the same.
-
You can also show just the headers. So if I just curl - i, this is useful for just seeing if something is online and what the content type is, etc., when it was last modified. Interestingly, this was last modified in October. And I would expect that to be much more static. And then you can just see the headers of a page instead of the actual content. You can also use wget. This is the same that we did with curl, but wget is just very simple. You don't have to do the dash O. It just simply downloads the file. So it also detected that we already had a readme.md file, but it has downloaded the same file. So the curl command is extremely useful and you'll be using it a lot. Next next let's check out viewing network connections and you do that with the SS command. And when you pass s s t u l n then it's going to output the following things.
-
These flags mean that you're going to be showing TCP connections, UDP connections, then listening server sockets. So processes that are listening on network ports on your device. And then the N is going to show the port numbers. So if we do it without N, then it is going to show the service names and that is not very useful. You actually want to have the port numbers like this. So this is showing all of the processes that are currently listening on your system. Here the these are not connected, but these ones are listening. So it's the SSH port 22 is for SSH. And that is running because we have um our system our SSH server running. So do you remember how to check the status of your SSH server on your system? Take a moment and check the status.
-
Status SSH. This is the the status of my SSH server. So here we see that it's running here on um it's still running on our system. And we can see that it has opened and and closed if you connections, but this is the service that is running on our on our um machine on port 22. If you want to see established connections, you can do SSH tun. Oh SS tun, I'm sorry. And this just showing the established connections. And in this case it is two connections. One of them being this session here and the other one being that one. Now we're going to be diving deeper into SSH because this is I I say this a lot in this course, but everything I teach you here is extremely important for your career. But SSH is really important because it's the main the main way you can interact with your servers. So let's dive into it.
-
Need some coffee to keep me going because this is going to be an a deep topic. Secure shell creates an encrypted connection between your computer and a remote server. Everything you type and all output is encrypted. So let's unpack this a little bit. We have an SSH session running here right now, right? So we have our computer and we have our Raspberry Pi. And we are making an SSH connection to this computer, right? This is what what's happening now. And because we said, hey, make a connection, the server is responding, okay, fine, but what is the password? And then the password was confirmed and now we have an SSH connection over here. This is the using the SSH protocol. Now this is encrypted. So if you're a hacker, you can actually be in a network and then you can start monitoring these kinds of streams.
-
And there's two ways of there's two modes that these streams can be. They can either be encrypted or unencrypted. And this is also related for example HTTP and HTTPS. So when you go to google.com in your browser, you're actually going to HTTPS.google.com. But if I do http.google.com, it actually goes it's in my browser is forcing HTTPS, but that means that it is encrypted. Your browser has a secure connection because you can see a certificate here. And the the connection is encrypted over https because it is over a a certif certificate. If I go to an it end think yeah, this is my self-hosted an it end server and I am running this on my Kubernetes cluster and I was a bit lazy and I didn't configure a certificate for this yet. And here it's going to say it's not secure.
-
So the connection is not secure. You should not enter any sensitive data because if someone would be on my network and I'm like for example updating my credentials or something he can actually just watch that traffic that goes on between me and my an it end server. And because it's over HTTP, it's not going to be encrypted. So he can actually view the traffic that's going on and maybe pull out the credentials that I'm typing in. SSH however is encrypted and that is why um I'm I'm taking some time to explain this because SSH is the it it literally stands for SSH for secure shell protocol. Secure shell. Secure shell protocol is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command line execution.
-
It is as a replacement for Telnet. So maybe you're old enough to have come across the word Telnet. I I have. But you for SSHing this this is why it was developed because Telnet is not secure. It's not encrypted. But SSH is. So when you are for example you're you're working as a DevOps engineer and let's say you are in the cloud and in the Azure cloud you have a virtual machine then you can connect into that machine securely over SSH from your home PC and you don't have to be afraid that hackers are going to intercept that from on the internet because this is completely encrypted and nobody can watch what's going on. That's why we are using SSH. So SSH has a few components. Is the client so that is on your computer, right? So on my main Linux system, my Fedora system I have an SSH client which SSH which is a command. So that is the client and then there is an SSH server.
-
Now the SSH server is the thing that we're checking with system sudo system CTL status SSH. It says here OpenBSD Secure Shell Server. This is the server that's running on our machine and this is there because in our installation process we said specifically that we want to enable SSH, right? That's why this is running on our system. So there's the client, so the command that you're running on your local machine and then there's a server on your server. And then encryption is it's unreadable by anyone in between. So when you run this command on the machine here SSH use if I run this command what's happening is that it connects to my server on port 22. They are going to negotiate encryption, so key exchange.
-
It's going to authenticate for my password. Then the encrypted channel is established and then I can run commands on the server. So it opens a channel and as long as the channel is open I can send commands to the server. So now we are using password authentication as you see here. That is the default that we was configured on our server. But this is simple, but less secure because anyone who has my password and if my server would be reachable from the internet, they can now actually um log into my server. Likewise, if you are running a virtual if you are in the cloud and you are running a virtual machine and if you have this as password authentication, then you're going to be noticing that in no time you're going to get millions and millions of requests of bots on the internet that detect, oh, this server has password authentication enabled. Let's try and see if it has any of the default passwords like admin, password 1 2 3, blah blah blah. There's like lists of default passwords and they're just going to try, were you dumb enough to, first of all, configure your system with password authentication and secondly, did you put a uh standard password like password?
-
So on our local machine, like if for learning purposes, this has been fine for now, but now we're going to learn how to actually properly secure our our server in terms of SSH. So we are going to be configuring key authentication. So instead of typing our password, we're going to be generating a key and using that for authentication. This is more secure. We don't need to enter any password anymore. It's based on cryptographic key pairs and it's required by many cloud providers. So many cloud providers will actually not allow you to do this. So to make this absolutely clear, like you've been seeing me jumping around in terminals and um like this, but for this, yeah, I'm going to open a completely new terminal here. Just to make it clear that I am in this terminal, I'm going to go and uh be in the temp directory. So if I you see the temp directory, you see I'm in a completely new different terminal, right?
-
So then you then you know what's going on. Here on my local terminal, so here let's just make a dir make dir local. See local. So now you see I'm in my local terminal running on my main workstation, my Linux machine. So when you're watching this course, you're playing your video on a device, right? And you're running the SSH command from a device. That's your workstation. That is where I'm running this. This terminal is not on my server or anything. This is my local terminal. In my local terminal, I'm going to run this command, SSH keygen T blah blah blah your example com. This is going to create a key pair with a certain cryptographic algorithm. In this case ed 519 which is the which is the recommended one these days. And then it has a an email as an identity.
-
It's going to create a new private key pair. So it's going to ask me do you want to save it here? In this case home Misha SSH and then the name of the key. That is fine. You can set a passphrase for your key. So anytime a key is used, you can set a password for it. This is more secure, but also requires you to type your password very often. So in this case, I'm going to just say no. I just press enter and enter and now I have created a key that has your email example com and it's located at home Misha. We have now successfully created our first SSH key. So if we go to my SSH directory, see in my well if I just LS home slash SSH, then we see there is already a few things here. There is another key key called workstation bootstrap, but this was the key that was just created, ID 519. These files have now appeared here.
-
Now that we have created our key, we now need to configure our server to actually authenticate with that key. So this has created we can check out what it has created actually. Let's just go over that one more time. So cat if I ls .ssh this we see that I have my ID like this and my ID pub key. Now these files are actually different. So if I let me just go in my ssh directory. Let's just see what has happened here. So if I cat the ID pub file we see that this has this has the this as content. So this is the what we also see when we do the the ssh keygen command, it outputted this. This is safe to share. This is like your public key. You you you can this is basically saying I am this person. Like I am this is my identity. This is your your your identity number. Well, let's put it like you have your ID card, right? And on that it you would have an ID number.
-
Well, that is this number. However, it also created this file and that is a secret file. You should never share that with others, but I'm going just going to show you what that looks like so you have an understanding of what's going on. So you have your public key and then you have your private key and your private key is actually the what what contains the the the secret. So when it creates this encrypted tunnel, it needs to encrypt the connection with something, right? And it's going to encrypt it with this. So without going into too much detail here, in short, what this means is that with this public key you have a accompanying phrase or or string of numbers and this can only work with this particular number. There's an algorithm that takes this then transforms it and this comes out and every time you're going to be using this key you're going to tell the server hello, I would like to authenticate like this. Am I allowed to come in?
-
And then it's going to verify with this key if you are actually that person. You need to have this file, this key file in order to prove that you are that person and if you have that key file then you are allowed to SSH in with this if the server is configured to accept this because that is going to be a next part of this. So we have a public file which is safe to share with people and then we have our private file which you should never share. Okay? So the now we we should configure our server to accept this key because currently the server again if I do exit here and if I SSH into the server it's asking me for this password, right? It's not using a key to authenticate and that's what we're going to change. So first on your local system and let me go back to my temp local. You see what I did there? I used the dash here. You have we've learned about that.
-
I'm on my local system and if the on my local system I have to add the key to my SSH agent that is running. So identity added here. So if you have been SSHing you have an SSH agent running. If I now do SSH add -l here SSH -l this shows all of the keys that are currently loaded into my agent. And you should see the output of your public key file that we saw earlier. You should see that here. Now I have a second one here. This is my actual SSH public key. It's not private. But this this key is my the key that I use for my own authentication. This is my public key file and I can show this because my public file, not my private key. But because this is here, this is now loaded in my SSH agent and I can actually um use a command that's going to automatically add the key to my server.
-
So before we do it, we have to just inspect what is actually going on on my server. So I'm going to SSH using my password like this. I'm now back in my Raspberry Pi. Now everything SSH related is configured in your uh home directory. If you do ls -la, you will see that there's a .ssh directory here. So if I go into my .ssh directory, we do see we now see that we have known hosts but nothing else. There's no configuration, nothing. Now what we do is on my host system, we're going to be running a different command which is called SSH copy ID. Now before you run this, verify with SSH add L that your key is actually here. If it's not, you have to re-add it by the command that we did earlier, SSH add. So you have to be running the your key must be here for this to work.
-
And I'm going to show you the workaround if it doesn't work. Don't worry. Now we're going to run the command SSH copy ID user at this. So this might the all the same command that I've been using all the time to SSH. I'm saying I want to go to this server, my Raspberry Pi, as the user user. And it's telling me, hey, two keys remain to be installed. And that that checks out because I have two keys in my agent. If you're prompted now, it is to install the new keys. So it is now prompting me with my password because that is the default mode of authentication to this server. So I enter my password. And now two keys are added. Now try logging into the machine with SSH user blah blah blah. So first, before we do that, we're going to see uh what has actually changed. So if I now do an LS here, I now see LS LA that a new file has appeared here, namely authorized keys.
-
Hey, that's pretty cool. Cat authorized keys. What is in there? Well, it's actually the the actually the same contents that I show that I showed you when I did SSH add L listing my current keys. It now now has added two public keys to this server. And that is how it's configured which keys are actually allowed to SSH into the server. I'm now saying I'm allowing this key and this key to SSH into my server. And actually, I'm going to VI this authorized keys file and I'm going to delete the first one. So I'm only going to allow the one that is on my um that we just generated just for clarity's sake. So if I now go here and if I now do SSH SSH uh into my server let's see what happens.
-
It didn't prompt me for my password. Did you see that? Again SSH I can just SSH directly now. So what's going on? It is now instead of asking me for my password, I'm able to SSH in there with my key. So we can actually see what's going on by doing the following command. Again, I'm on my local machine and I'm running SSH V user. So now it is showing me all of the output. So the V flag usually is called um verbose and it's going to show you all of the output of the command. So now it's reading configuration data. Then it's going to see are there any identities here? Then it's going to see the known hosts, right? In the in the server. So first it's authenticating as user and then it's going to reply the server host key.
-
Okay. This is the key that we are going to be authenticating as. So it found the key in home Misha known hosts. So this is the key that we we we would accept. That's what we're saying here. And then oh I found this key in known hosts. So let's just authenticate with that then. And now it did that and it is will attempt key card no. Well we deleted that one so that didn't work. But now it's I'm going to attempt another one. In this case the ID 519 and it says offering the public key and the server accepts the key. And now I'm I'm authenticated using public key, right? I didn't use my password. It's using the public key and now it's working. Next to my server over SSH using my key. Now what we want is we want to disable the password authentication because that is insecure, right? So again I can now be on my system and if I run SSH I can SSH. Now it 's not asking me for my password anymore. So I know that I'm using my my key.
-
But now we actually want to make sure that the server does not allow any password connections anymore. So we do that by going to by SSHing into our server again. And then we are going to modify on the server that we are in. So again, be on the server. I'm on my Raspberry Pi, not my local machine, but on the server we're going to edit a file with VI that we have learned, namely etc SSH SSHD config. Now as an exercise find this line in this file. Use use the use a command to find this this line in the file. How would you do that? You can go and type the slash and then pass. Remember that you need to use the the case sensitive search.
-
Password authentication. Then we're going to remove this character by pressing X. And then I'm going to go to the end of the line using the L. And then I'm going to just XXX and then insert I'm going to say password authentication no. We do not want to allow any password authentication. Okay? Then we have the pubkey authentication yes. So let's search for pub. Oh, I'm not finding it. Why? I didn't include the capital letter. So pub. Pubkey authentication yes. And this this hashtag in front of it means that it's commented out. So it's not being set currently. So if I remove that now it's saying pubkey authentication yes. We are allowing pubkeys to authenticate.
-
And we are going to disable password authentication. We are not allowed to use password authentication anymore. So that is now done. Um to actually make sure that we are able to log in, we should um we are going to restart the SSH server, so it's going to load the the new configuration. But before we do that, let's just make sure that we have at least one session open. So we have our session open here. I am at user at Cato. This SSH session is still open. It is still running. So I'm going to um systemctl restart sshd now. Uh SSH, sorry. The service is now restarted. So sudo systemctl status SSH. It is now restarted. And now we can test whether we are actually able to log in again. So exit, clear, and let's SSH back into it. And yes, it is still working. So now we know that we can actually log into our server with our SSH key. And now we can safely close the other servers if if we wanted to.
-
So if you don't keep that session So if you don't keep that session open, then you are risking locking yourself out because if your SSH key authentication isn't working for some reason and you're then disabling password authentication, you are now unable to log into your system anymore. So make sure that you um keep at least one session open, test it in a new terminal window and make sure that you can log in. And when when it works, then you can do it properly. Exit. And now we can set now we can set up our SSH configuration on the host machine. We are going to go and again on my host machine, on my local machine, I'm going to go and run the command um sudo no vi home ssh config.
-
Now my my config already has a bunch of stuff happening in it, but yours probably will be empty, but I'm just going to go to the bottom of the line and here I'm going to add this um this these few lines here. So host kato. The hostname is one and two. So this is the IP address. The username in my case is um user like this. And then the identity file is pointing to the private key that we generated, 519, right? So I can now close this. And now what I can do is if I just do ssh kato, it is going to find the IP address in the ssh config file. It knows which key to run and which one to use to authenticate with it and it is um authenticated to the server properly using my ssh key. So instead of having to do ssh user at blah blah blah, I can actually now just do uh ssh kato and boom, I am here.
-
Much cleaner, right? Super cool. So in this module we have learned a lot about um ssh. Now we're going to do um some copying over ssh. So let me see. We are going to uh copy a local file to a remote server. So I'm going to exit the ssh session and I'm going to go to temp and local here. I'm on my local machine and let's do a touch uh file .txt. And then we're going to do a secure copy of file txt at at uh user at kato. And we're going to put that in /home. If I press tab, it's actually going to complete already, user.
-
And let me see, does this have Yeah, so it does not have a file called file.txt in there. So I'm going to secure copy file.txt from my local machine to kato at home user. And if I now go on kato and if I LS now, I see that my file.txt is being copied over there. Pretty cool, right? We can also copy files from the remote server to our local directory. So since we have configured as SSH, so we should be able to do SCP kato. Yeah, that that should should work. So SCP kato and then from kato in home user we're going to take readme.md and copy that to our local directory.
-
And if we do cat readme md boom, here is our file scientists learn from books. So this is how you can copy files to your server and from your server. You can also copy directories by adding the R flag. So to wrap things up there are a few SSH best practices being using keys, not passwords. Use a passphrase on your key, even though I didn't demonstrate it, but you should do that if you want to have have security on your key. So this way if someone gets access to your key files, they still would need to enter the password. Use the config file so you can just very simply simplify the SSH command by SSH kato like this and specifying which key it should use. And always always keep your private keys private. You can you can share the dot pub file and the contents of that.
-
That's totally fine, but always keep your private key files private. Here's an overview of the everything that we've done. And as a challenge, this might be a bit harder if you are doing this on a Raspberry Pi, but if you happen to be using a virtual machine, you could actually spin up a new one and go through this entire exercise again to see if you can create a key, configure your server to use that, and then disabling password authentication and making sure that you understand this from scratch because this skill this took me a long time to actually learn in the beginning when I was starting out. But when you learn this, it's going to make your life so much easier when you're going to be running things in the cloud and even when running containers actually. Sometimes you even have to use SSH for that too. So this was the primer on SSH and I'll see you in the next module. If you've had trouble getting SSH to work, connecting to your server, or figuring out why something broke, do not worry. These are exactly the problems you'll hit when working with Linux and learning to solve them is part of becoming a better engineer. But you don't have to figure it all out alone. In our free Linux course community, you can ask questions and get help from other learners and follow the course module by module. Join for free using the first link in the description below. All right, let's continue. Welcome to module 11 where we
-
are going to be learning about tmux. So you have been seeing me use this snazzy thing where I have a few different windows open and I can switch between things and I haven't told you anything about it. So we are going to be changing that because the thing that makes all of this possible is called tmux. This is a bit of a strange name, but we are going to um explain why it has that name too. So, what is tmux? Why do I need it? And uh let's go into it. So, tmux stands for terminal multiplexer. And this solves a problem where imagine you're running a long process over SSH and your connection drops but and without tmux the the process dies. You have to start over again. Or you're working on a server and you need to watch logs in one terminal, edit the files in another and run commands in a third. That's what you see me doing here, right?
-
Well, without tmux you would need three different terminal windows and SSH connections. And for example, on these terminal emulators that we learned about you just have your one little screen and you need to be able to do multiple tasks. That is what this um what is solved with this. So tmux let's uh see. tmux solves both of these problems. It's it persists sessions, so you can disconnect and reconnect without losing work. You can split your windows and and and views like this, like you see me doing. And you can um have tabs like this uh in the top here. So, getting started we are going to go to our server and again I'm I'm doing this in a completely different window. So, in my temp local and I'm going to SSH back into Kato. And now I'm back in Kato and I'm going to uh write which SSH um which tmux.
-
And tmux is actually already installed. Well, if it wasn't installed then you just do sudo apt install tmux. And it's now it's just going to check but it's all it's already installed, so it's going to say fine, you you don't need to do anything. So, or command v tmux is going to show that we already have tmux running or installed. Now, to run tmux, you simply type tmux and that's it. This is, this is tmux. This is the default configuration of tmux that you're seeing here. You're now inside a tmux session and the green bar at the at the bottom, that is the status line. So this is the status line and this is going to show you what's going on inside of your tmux session. And now we can start issuing commands to tmux. So tmux has a set of commands and in order to send a command, you first have to press control B.
-
Control B and then the first one that we're going to do is control B and then press D and now tmux is saying detached from session zero. It's saying we are detached now. I'm back in the normal shell, but the tmux session is still running in the background and we can even view those sessions. So if I now do tmux LS, we see that there is one session, namely zero with one window and it was created. And if we want to go back to that session, we can either we can do tmux attach and then it's just going to attach back to the first session it finds. Control B D and if I now do another tmux and if I do control B D again and tmux LS, now I see I have two sessions here. So if I then tmux attach and I simply type exit here and note this one says one here in the bottom.
-
That is corresponds to the tmux session that we saw earlier. And if I simply type exit here, it is closed, it closes and tmux LS, now there's still one session here. So that's how you can see the sessions that you have going on at the moment. So tmux attach to attaches to the most recent session. And if you want to attach to a specific session, tmux ls. Let's create another one, tmux and then control b d. tmux ls. If I now want to attach to session two, I can do tmux attach t two. And now I'm back in two, as you see. Exit. tmux ls. Now I have one session left. You can also create sessions with names. So let's do a tmux new and then call it name. So tmux new as work.
-
And now you see down here it says work. And if I control b d now, tmux ls, I see that there is one called zero and then there's one called work. If I want to kill a session, so let's just kill the one that has I don't want to use that work session anymore, you can run tmux kill session t work. And now tmux ls shows there is still one session left. tmux kill session t zero. [clears throat] tmux ls and now there is no server server is running on my server again. So and as you as I showed you from inside tmux you can just type exit and then you exit. So let's learn about windows in tmux. So when I open up when I run a new tmux session here and then let's create a new window by doing control b c.
-
And now you see in the bottom of the of the screen a new window has appeared and this asterisk shows which one is currently active. So I can do echo session one. If I now press control b n I switch to a different one. Control B n, I'm back to session one. Control B n, I am now back in session zero. Echo, this is session zero or window zero, I should say. This is window zero. Control B n, session one. Echo, this is window one. Let's make it a bit nicer. Control B n, control B n. And control B like this. We can also go to next window or previous window with control B p. You can do it by [clears throat] number. So if I go back and if I just control B c, control B c, control B c, now you see in the bottom I have a bunch of windows.
-
Now if I do control B three, I am now attached to number three. Control B zero, I am in window zero. Control B four, and I'm in window four. To close them, exit. Or if I do control B three, I am now in window three. I can also press control D and then I exit as well. To rename a window, you can do control B comma. So let's go to control B two. And I'm now in bash and do this with me. Control B comma. Rename window bash to Misha. And now we see that number two is renamed to Misha. Control B zero, control B two, and the window is named Misha. So then you can see you can name your panes. So for example, control B zero, control B comma dev environment.
-
Like this, that's my development environment. And control B one can be control B comma logs. So here I can do journal CTL F. This is the one that has my logs. And control B zero is has my actual dev environment. So I would enter VI here, for example. So now you can see how this is going to work. I can be I can be editing my text file in here. Then I have my logs in the next window, like this. And I have some other stuff going on over here, for example. So sudo su sudo dash I. Just say echo hello and exit. Then I see here in my logs that there was actually a sudo event happening and I can go back to my dev environment and continue working, right? So now you see that inside of just this one window, I can do many different things at the same time.
-
And I can um have Yeah, I could do work in multiple windows on the same server. All of this is running on my Raspberry Pi. So And then the nice thing is I have all of this work going on in my dev environment. But if I want to exit, I do control B D. And tmux LS. And we see that this is now saved in a in my tmux session. If I exit the connection and I am now in my local server, so cat uh OS uh Etsy OS release. I am on my Fedora Linux server in this session now. I'm in temp local. You know this is my local session. If I now SSH back to Kato and I do And like I have nothing running here now, apparently, right? Like I'm I'm in my home directory. There's nothing going on here.
-
Tmux LS. Wait a minute. This is still here. Tmux attach. Boom. I'm right where I where where I um left off. Isn't that cool? And again, the logs are showing accepted public key, etc. So I can now use my Raspberry Pi as a workstation. I can do development work on here. I can do bash, I can write code, I can do so many things. And when I'm done, I just do control BD, I detach from my session, I exit, and everything is going to be saved as it is as long as my machine is powered on. SSH, tmux LS, tmux attach, and we're back in business. Now we're going to learn about panes because you windows are great, so I can do control BN, I can switch between these. But what for example, if I want to have my dev environment and then have my logs beside it? I don't want to be switching around all the time.
-
Let's say I want to have my dev environment here, here. And I want to have a session with the logs beside it. With this, I can do control B quote. Now I have the logs under it. So I can have journal CTL F. And if I now do sudo cat let's see password like this, then we see that I in real time I'm going to see these logs being streamed because I'm triggering these logs to be added by catting Etsy password. So that's pretty cool. If I now want to enter this pane, I do control BO instead of control BN or PK control BN is to switch between the windows. Control BO is switching in the panes. So this is a pane and these are the windows. Those are two key key subjects, key words that you need to remember.
-
These are win windows and these are panes. These extremely important to know this to understand tmux properly. Now, Ctrl b o, I'm in here. I can control c to exit out of this. Let's Let's exit this pane by just typing exit. It's going to close it. Now, let's split it like this vertically, and I did that by pressing Ctrl b percent like this. So, Ctrl b shift 5 [snorts] control control b percent. That is the way to do it. Control b percent. Now, I split it like this. I can do journalctl - f control b o to switch back. Now, I can do another sudo Let's do a sudo cat at c password, and now I see things happening in the logs as I'm as I'm doing this.
-
Pretty cool, right? So, now I can do some really cool stuff if I just split this one as well. And let's say I want to do the SS uh till like this. I can have that open, and then I can keep working over here. So, this is how you can do many different tasks at the same time and create a really nice little environment for yourself completely from the terminal. And this is how I work. So, you see me work in this course. I I've been having many different windows open. I have SSH Kato open over here. I can have my Fedora um session open over here. All of this is happening in tmux. So, in I I like to say that tmux is my window manager. I do almost everything All of the work that I do, I always do that inside of tmux. So, when I start my my computer, I instantly start tmux and just start working from there.
-
But you don't see this this bar under here, right? You don't see the the the bar that you see on this screen. So I have done a little bit of modification to my session because I like to have the the stuff. I like to [snorts] have my bar on the top and I don't like that ugly green um bar. So we're going to be learning how to um configure our tmux session in the next uh section. So we've learned how to split them and how to uh split the panes. And here you can also when you have so many panes running, so let's split it vertically again and do another one here. You can also navigate with the arrow keys. So control B up arrow, control B down arrow, control B left arrow. And here we go. This is um this is how you can navigate the gate between them as well.
-
Now there's one important piece that I have to impress upon you and that is the tmux key bindings. The control B shortcut is a little bit awkward, right? It is it feels like a bit weird to do control B like that. But many many people like I would say the majority of people make the mistake of remapping their key bindings in tmux. There's plugins for this. There's easy ways to do this. But if you change the default key bindings for tmux, you are severely severely limiting your capability of being productive on any server in the world. We have already learned VI. We are using the bash shell. Those two things are available to you on any server in the world.
-
In many containers it's going to be there. Now tmux is going to make you dangerously productive on any server in the world because you can now have multiple sessions and you can do so much work at the same time no matter where you are as long as you have tmux installed. Tmux is not always installed on every server, but it's a very small program and it is usually part of the system standard system administration toolkit that you're going to be working with. So tmux has a very small footprint and that is fine to install on servers if you want to be productive. Now if you remap those keys and you like I know I realize control B percent is awkward, right? It is it feels a bit awkward to do that. There are people who will then remap that to um control B uh control B pipe like this. So to so you remember that this is the you want to split it like this and control B dash to split it like this.
-
Some people do that and it's not a bad idea. I I like that because you remember it better. However, if you do that and you are used to doing this on your own machine because remember here tmux is running on my own machine, right? This is just my own personal environment that I control and there's no I can just do whatever I like on here. But I purposely purposely do it not change my key bindings in tmux because I am able to create my tmux session on the Raspberry Pi here and you don't see me struggling with commands here. I can I can easily just tmux open new one, open the open a um pain, split this one, open a new window, navigate between them and if I want to go to this window, go to that window, I I have no problems navigating around because I know the exact key bindings.
-
It is like ingrained in my in my system now. I can very easily move around and be productive in tmux because I have built up the muscle memory. And I can only do that on this Raspberry Pi because I know the defaults. If you're going to change this and you're going to be SSHing into servers that do not have your precious config files, you are not you're going to be struggling. So oh, oh yeah, okay, tmux, okay. Yeah, in my own system I do control B pipe, but that's not going to work here. Control B minus. No, that's not going to oh damn, it's not working. How was it again? tmux help. tmux help or man tmux. How did I do that again? Split. You know, you don't you're not productive. If you're you're productive, if you can tmux control BC and it's any server of the world, it is exactly the same. It's exactly as you expect it to be because you have learned the standard key bindings.
-
So yes, they are a bit painful to get into the system. Control BC, it feels weird, but take this advice from me. This like this was impressed upon me by some of my best mentors that I had in the beginning. Two things, three things. Use Bash as your main shell. Learn how to use VI and use the standard key bindings for tmux. Learn them and they will serve you for the rest of your life. tmux has been around we can we can look it up man tmux. tmux was created man tmux. Does it say here? It actually does not say here when tmux was created. When was tmux created? tmux was created. Open source 18 years ago. tmux was created 18 years ago and it's still it's still around and it actually its predecessor is screen.
-
Yes, no screen. I don't have screen on my system. Which screen? Screen is actually um available on this system, but I'm not even going to run it because because I don't know how to work with it. Screen is even more universal, but it does have a lot less functionality. And tmux I would I would recommend not learning screen, just learning tmux. Screen was the predecessor, but tmux itself is 18 years old and it's going to be around for 18 plus more years easily. There's so much that you can do with tmux like copy pasting everything everything is integrated into tmux. If you know learn it well and use the default key bindings, you're going to it's going to serve you for the rest of your life. So if there's one thing you take away from this course, let it be this.
-
Use bash, use vi, and use the default key bindings. Okay, so now we have set up our tmux. We know how it works and now I've already shown you the editor on the left, the logs on the right. Here's the command overview and now we can move on to the final section where we're going to be doing some customization. Welcome to the last module of this course, our terminal setup. So we're going to be learning about how to configure our terminal and how we can customize a few things. So first of all, we're going to be answering what a dot file is. You may have been you may may be familiar with the term dot file, but I'm going to be explaining what that is, how you can configure your terminal, your vim, and your prompt. So let's dive into it. Understanding dot file. So what is a dot file? So if I go to my home directory, and if I ls la here, we're going to be seeing a few files here. And one of them is the .bashrc. So dot this dot dot files means a hidden file.
-
But because when I do ls, you don't see the file right? Well, a dot file means a hidden file, but a dot file specifically means a hidden configuration file. So dot files refers to files that contain configuration for your specific that contains your specific user configuration for your tools. So for example, for vim, there are configuration files that where you can set the settings that you like. Now, I've prepared [snorts] a little bit for this one, so I'm just going to remove the .vimrc. So and let's just clean up our .py and our .txt and our .md. So everything is nice and clean. And let's remove that last one too. Okay, so everything is nice and clean now. And then we can Now, but we we've seen that there's a bashrc, profile, a lot a few different things. So these are configurations for your shell editor and tools.
-
So let's start with the bashrc then. So cat .bashrc. This contains a bunch of configuration for your bash shell, your specific shell. So your for example, we have a hist size setting the history length. So our history file is now 1,277 lines long. But if we open our bashrc, this is set to 1,000. So if we have more than 1,000 commands in here, it's going to remove the old ones, for example. Now, this bashrc is configured by default uh through um your through Ubuntu. So, when you installed Ubuntu, Ubuntu server, it came with this configuration file um and it has installed it.
-
[snorts] I I'm not sure if all of this is done by the Raspberry Pi install installer or that when you download Ubuntu server in a VM, it's going to do the same, but your .bashrc file is likely to contain some things. Now, we also see a .profile. So, if I open up that one, vi .profile, here there are a few different things that are happening. Um in like these files are loaded differently. So, we have the profile and the bashrc. The profile is for login shells and it loads your environment variables and path. We're going to be diving deeper into that in the containers course, but and the bashrc is going for interactive non-login shells. Now, we're going not going to go deeper into the difference between active, interactive, login, non-login, but if you want to, you can do non-login, login shell uh Linux.
-
You can [snorts] read about a You can read about that difference between login and non-login shell. There's plenty of material out there, but it comes down to when you SSH into a machine, you will be opening a login shell and non-login shell when you open a terminal window. And active and interactive depends on whether the shell is going to be for a user or a script. So, these two files, they contain different things um technically you can be configuring different things in each file, but in practice this, as you see here, this file is loading the bashrc and in practice all of the configuration for the shell is happening in your bashrc file. So, this bashrc file is an example of a dot file which contains specific configuration of your shell. So for example in my um in my case I am actually using echo shell. I am using Zsh and this is because I've been running Bash for well over four years as my main shell and that's when I switched.
-
So uh echo I'm using Zsh and if I go to my home directory and I can open .zshrc this contains all sorts of configuration for my Zsh. So it's all specific configuration of about things that I want to have in my shell. And we're going to be looking into that when we're going to be configuring our prompt. So let's dive into that the prompt. Now the prompt is what you see here, right? Prompt. This is the user at Cato prompt. When you see my prompt here on in my Zsh configuration here when I CD into a directory for example you see this is changing but if I enter a Git repository so if I go home lab here and then home here you will see that this is now going to show for example the branch that I'm in. So my prompt is being updated and this is I like have having a very minimal prompt and only showing where I am and the Git branches.
-
Git is the the topic of the next course that we're going to do after this. But um it's suffices to say that my prompt shows different things based on my location. Now this one does a similar thing if I go to home or CD temp then it's actually showing me where I am but it's just a single line prompt and it doesn't do much much else, right? Now you can um configure this prompt through Bash or C directly by changing colors, etc. But that is actually a whole science of its own. There is the prompt variable, bash prompt variable here. Um so there is controlling the prompt in the bash um reference manual. Actually, if you do man bash and search for prompt, you probably get the same What does it say?
-
Controlling the prompt. So controlling the prompt. No, it doesn't include it in the man page. So controlling the prompt it this is going to show all sorts of variables that you can set and you can um uh do it. And the variable the variables for that are PS0, PS1, PS2, etc. So you can actually code your own prompt in that sense and it's a bit of a science of its own. What another way that I found very useful for teaching beginners is to use Starship. And Starship Let's do Starship prompt is a minimal, blazing fast, and infinitely customizable prompt for any shell. So with Starship, you can very quickly get a really cool prompt with all sorts of functionality and uh it's very easy. I am not using that myself. I am using a very minimal prompt. I don't actually like a lot of stuff in my prompt, but I know plenty of people who love having tons of stuff going on there. So I'm just going to show you how to do it and in the best and most easy way possible.
-
So to install Starship, we install we just curl this. So we've learned about curl. In general, you have to be very careful with curling and especially curling shell scripts from in command line because what this does is it basically curls a large script, and it's going to execute all sorts of commands on your machine. So when you have learned bash scripting in the next course, then you can actually you'll be able to determine what this script is actually going to do. And in general, you have to be careful with just curling something and running that as a shell script. So I want to emphasize yes, this is obvious this is a big project and it's not likely that this contains malware, but if somehow the developer of this goes rogue and he puts something in here that's going to I don't know read your Bitcoin wallet or something like that that happens often, that can actually happen. So uh I I'm not going to say that you can just blindly curl anything like this from the from the from the internet.
-
That being said, we are going to run this and this then is going to install starship latest to user local bin. So it's going it's simply a single binary. So it needs to have administrative permissions. So this is already like at this point you may want to start reading the script because hey it needs admin privileges. What's going on? But we trust this so it's okay. It is now installed and now it's going to show us a few directions. So please follow the steps for your shell to complete the installation. So it has now installed the binary to our system, but it's not being loaded into our shell yet. So for bash, it is showing note that bash is the first one that they are showing evil evil starship in it bash. Then they are asking you to add that to your bash RC. So we've learned how to edit files. We go to the home directory and we do VI and that is technically Vim, but let's for for for fun's sake do busybox vi bashrc because we want to have the old um old-fashioned way.
-
And we are now in the top of the file. We go to the bottom by pressing shift G. I'm now in the bottom of the file. And in the bottom of the file I'm going to paste in evil starship init bash. I'm going to save that by pressing escape w q. And let let's do a check here. How do I see the last line of this file? Do you remember? Or the last five lines of that file. Do you remember how to do that? If we want to see that we run tail bashrc. And we see now that our file has successfully been updated because at the tail of it we see our starship init bash. Now we have added this but hey it's not loading yet. Our prompt is still the same. So what's that all about? In order to load this file your your your your shell your bashrc is loaded when you log in.
-
It is when you start the session that's when the the file is loaded. But when it's loaded it's not being reloaded anymore. However if you want to reload it you do that with the command source. So source and then from the home directory we're going to do bashrc. And if I source that now I see that my prompt has changed. Look at that. User in uh world Kato in home. User So I yeah I don't even know what what all of that means because I I don't use starship as much. But I am now I see a very different prompt that I had before right? User in world oh oh host Kato in temp. So my user user in the host Kato in temp. Cool. Now let's see how we can um adjust this, right? How can we configure this? So if you click the configuration here in the Starship documentation, here's teaching us how to configure it. So to get started configuring Starship, create the following file, .config/starship.toml.
-
So it's telling us how to configure it. And again, this is um it this is another dot file, but note this is not a hidden file as such, but it's located in the .config directory. And this is a convention that you will see that is called XDG config home, XDG base directory. Uh so XDG config home is where user specific configuration should be written in home.config. That's what the convention that they're following, and that's what I strongly suggest you do as well. So we're going to make there a directory in .config and we're going to create a starship.toml file. Now we are going to be adding a few things to this TOML file. So um this is just the default configuration, right? So let's do let's use vim now.
-
vim .config starship.toml. It's an empty file because we touched it. But now let's just um insert the contents and note now this character has changed to this. So it's automatically reloaded already, right? So the prompt is now different. It has changed from this character to this character. So we've changed made a change here, and now we can start configuring our shell. So our prompt, I mean. So on this page, there's so many things that you can do, and I invite you to um yeah, take a look at what you want. But I'm just going to add a simple one here uh memory usage. So we remember how to use um how to check our memory, right? Free dash h.
-
In this case, I'm we have 20 20 266 megabytes used memory currently. Let's say I always want to see that in my prompt for some reason. Then we can copy this code and then we are going to open our starship.toml file again and we are simply going to add this here. We can remove this. Okay? So disabled false, threshold and symbol and the style. And yeah, all of these configuration specifics you can uh learn on your own. But now we see that my prompt now has um memory usage included in it. And you see it's changing a little bit here and there. So this is how you can configure your prompt very easily through this configuration file. And there's tons of possibilities that you can do here. There is uh status, there's Terraform, uh what what other things do we have? OS.
-
In case you want to make sure that you are running on Linux, there's all sorts of stuff that you can do. So starship is one to um to look into. Now this is this is a lot of fun to make your prompt nice etc. So I definitely you should check it out and and go for it. But some if I can give you some advice, don't go too deep into the whole configuration rabbit hole because early on in my career I must confess that I spent way too many hours on getting everything just right. And in the end, I have just ended up with an extremely simple prompt with a few colors that I like and that's it. So uh don't go too overboard with this. Don't spend too much time on it, but it is a lot of fun. So, do. Definitely do it. So, now you have a super an amazing prompt in Bash and it works. So, this is what's here in this file. We've already done all of this.
-
Now, let's look into configuring our Vim. So, we have now been using VI for a while. We can now start using normal Vim. So, Vim comes with a custom or a default configuration file. Let's just ls la our home directory. We have no Vim RC here, but if we do cat at C Vim Vim RC, this is a configuration file that has a bunch of settings in it. So, we can if we copy that file to our home directory and call that Vim RC like this, now we have a Vim configuration file. And let's just open that with Vim itself. So, this file will have a few configurations in it already. And the the quote character here is the comment. So, if if if there's a quote in front of it, then you will then it's actually it's just a comment. It's just text. You won't it won't be loaded.
-
But here it says uncomment the following to have Vim jump to the last position when reopening a file. Okay, that's pretty cool. So, let's try it out. We are going to save this and do we have any files yet? No, we have not. So, let's just open a test dot pie file. And we're going to write some Python code. Very simple. So, I'm going to write def hello like this. And I do two spaces and I do print hello world. And then we're going to call this function by saying hello. Hello, like that. This is a very minimal Python program. Now, note that my cursor is now in the word print, right? It's not at the top, it's in the word print. If I now save and quit this, W Q, and if I open up vimtest.py again, my cursor is actually saved where it was.
-
If I turn that off, so my cursor is now in this fourth line, I'm going to save and quit. I'm going to open the vimrc. And here also it is remembering where I am. But if I put the quote in front of it now, and exit, and go back to test.py, I'm starting at the top. So we see that our our our settings are taking place. So let's open our vimrc and go through some more settings. So this our buff read post, let's uncomment that. Then we can uncomment the following to have vim load indentation rules and plugins according to the detected file type. So yes, let's do that. I just press X to remove the comment. And then there are a few more more settings that we can do. So for example, set ignore case, do case insensitive matching. That is an interesting one. So let's enable that one.
-
And also if you're a beginner with vim, you may want to open set mouse, so you can in in some cases use your mouse. Let's just keep it at that for now. We have a few settings set now. Exit. If I then open test.py again, if you may notice you you you notice that when I wrote our first function, we actually were um we needed to do press space space, but if I now do def world and press enter, now it's doing automatic indentation. So print um auto indented. I don't know. Doesn't really matter what we're writing here. But it's giving me some syntax highlighting. It's looking good. If I make a mistake, it is also showing me something here because that was a mistake. Okay.
-
And then let's run the world function as well. And now we have written some Python code. I can now do Python three test dot py. And oh Python is actually not installed. Uh sorry, I made a mistake there. Python three test dot py. Here we go. So now it's running our Python script. Hello world and auto indented. Pretty cool. And like the Python specifics, we're not going to get into that here, but I'm just showing you the text editing and that it is working. Now we also set this um ignore case, right? So if I now search for hello, it's going to it's going to match all of the following. So if I press n, it goes to the next one. And this one actually has a capital H, right? You see this hello, this has no capital. This one has a capital and it's matching. So it's case insensitive.
-
Okay? So if I now want to disable that, if I press colon and I do set ignore case and then an exclamation mark, I'm turning it off. If I now search for hello, it is not going to match the hello with the capital H. You see? That is the difference and that is the setting that we have just created. So we now have our basic VMRC and we are we know how to configure it. Now let's move on to the next one which is our tmux configuration and of course all of this is optional but when tmux starts it's going to read the tmux.conf on startup. So let's check out we don't have any tmux.conf running here. Tmux LS there's actually still a tmux session running so let's just tmux attached there and oh this is our tmux session well let's just exit it and tmux LS so there's no server running on my machine anymore.
-
Now to do some configuration we can I'm just going to copy this on the on the server I'm going to do vim and then home dot tmux.conf and I'm going to paste this in. Now what do we see here? We have set g base index zero so let's let's see what that means. So if I'm I'm here on my session again right? I'm in I'm in Kato and you see the prompt has not updated here because I haven't sourced my bashrc. Actually I could just source the bashrc here and now I have my new prompt. Pretty cool. Now tmux LS no server running. If I run tmux now then we see that this server is starting on zero. Control BC control BC control BC zero zero one two three this is a programming convention where the first number is actually zero.
-
Now for me when I am switching between this control B one control B two it doesn't make zero sense for me if I do control B that the first one is going to be zero on the top right. Like in my mind I don't like that because if I want to go to the first one it's just one two three that makes a lot more sense to me. Instead of going to zero, just starting at one. So what we want is we're going to set the base index at one and the pane base index at one. So when we do this, then we're going to see that we can actually um that that it will start at one. So let's do that. I have now saved the file. I can exit or press control D, control D, control D. Okay. Tmux LS. There's no server running. If I now run tmux, we see that it now starts at one. Control BC, control BC. Now it starts at one, two, three here.
-
Also, I can now click here. We also set something else. So let's take a look at the other settings that we just set in our tmux configuration. We have set the mouse on. We've also increased the history limit because tmux also saves its own um history. And we are adding a two 256 color support. This is sometimes needed to um properly display some your some of your colors in the terminal. So this is a very minimal base configuration of tmux, but which does have some sane defaults that I think are important for ex- it's not important, but I like to have to add it to start at one. And you can just go and configure it from here. There's so much you can do, but at least you know how to do it, what file to create, and how to um how to get started with this. Very it's again an important part of the Linux command line fundamentals.
-
So now you have all of your um all of your configuration done and we have uh learned how to put these into files. Now the next step is going to be to save these files somewhere, right? Because if we're going to be running our servers on we're going to be running our environments on different laptops, different servers, in our home lab. Like my current home lab has over nine devices running at the same time. So in my own home stuff, I like to have my own shell environment, etc., available to me everywhere. So we need a place where we can store these configuration files. Now in this this is now going to be the end of the Linux course, the Linux command line fundamentals. And in the next course, we're going to be learning about Git, which is how we can um have source control on our files and a place to store them that is accessible anywhere from the internet.
-
So that is going to be the next course that I suggest you do after this. Um and I'm going to go a little bit deeper into some suggestions for further study and the next steps after this course. So I'll see you in the outro. You're almost at the end of the course, but before you finish, there's one final challenge. We've created a 50-question Linux skills check covering everything that's inside of this course. Some questions test your understanding and others make you run the commands and prove that you know what you're doing. Your goal is to get all 50 of them right without looking at the solutions. Get one wrong, go back, practice it and try again. Download it completely for free inside of the Linux community. It's the first link below in the description. Congratulations. You have now reached the end of the CubeCraft Linux command line fundamentals course. This is the course I wish I had when I started out and you now have all the skills and commands to securely manage a Linux system.
-
So you have done this on a Raspberry Pi. You're doing this in a virtual machine, but um it doesn't really matter where it is now. You can do this in cloud virtual machines and this is the start of your command line journey. I have given you the fundamentals, the basis from where you can start building your own um command line empire. And in order to help you with this, I have suggested a course progression for you after this. So in the next course, the Git Fundamentals, we're going to be taking starting with these dot files and creating a setup that we can um put anywhere in the world and become have our own configuration on any server that where we work on. Next we're going to be learning about Bash scripting. So we have been working on the command line and just running these commands. But if you start stringing them together, then you're actually running scripts. And that is what the Bash Scripting Fundamentals course is going to teach you.
-
After that, I suggest you go for the Container Fundamentals and then you're going to go for the Arch Linux from scratch. So if you are a member, you go to the classroom and then you go to DevOps OS part one and you go to Linux and here there is the Arch Linux course. Now this is going to teach you Linux on a on the next level. This goes super deep into mounts, designing a system from the ground up using system d, encrypting it, which is very important. Security it is it has everything. So definitely um I recommend doing that one. And after that, we can we're going to go into the Kubernetes fundaments. In the meantime, if you want to keep studying Linux while you are working on the Bash scripting and Container Fundamentals, I strongly recommend you check out this book. The it's a bit of a tome. It is heavy. It is but it is amazing.
-
It is um available at Amazon here, the Unix and Linux System Administration Handbook, fifth edition. This is by far one of the best resources on Linux ever written. So I strongly recommend you study that one if you want to keep going with this um uh separately. And uh for now, thank you going through this course. I um I wish you all the best of luck on your command line journey. I have given you the best practices that I wish people told me in the beginning and many of which that I have learned the hard way, but also from some very good mentors that have brought me to the place where I am today. So it was a pleasure giving this to you and I'll see you in the next course. Congratulations. You've completed the CubeCraft Fundamentals Linux course and you now belong to the top 10% of computer users because you know how to work on the command line. If this course helped you, share it with someone else who's trying to learn Linux or to land a DevOps job. Linux is only the beginning, but if you want to take this one step further and you want to land a DevOps job, you can download my DevOps roadmap for free by following the link in the description below. But if you want to keep practicing Linux first, then the workbook and the 50 question assessment are cubecraft.dev/linux and both are completely free and they're also linked below in the description.
-
Thank you for spending these 8 hours learning Linux with me. Now go practice what you've learned and I'll see you in the next video.
Summary
This comprehensive eight-hour Linux course is designed to equip aspiring software, DevOps, and AI engineers with essential, hands-on command-line skills. The curriculum covers setting up servers, mastering the file system, permissions, processes, networking, and SSH, with a primary focus on using Ubuntu Server. The practical takeaway is to move beyond superficial tutorial memorization and develop true troubleshooting competence on physical hardware, establishing a solid foundation for modern tech careers involving Docker, Kubernetes, and DevOps.