Linux Crash Course - Connecting to Linux Servers via SSH

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[MUSIC] Hello and welcome back to my Linux Crash Course series here on Learn Linux TV. In this series, we tackle one important foundational concept around Linux, one video at a time. And most of these videos are actually completely stand alone, so you can watch them in any order unless I let you guys know otherwise. In today's video, what we're going to do is take a look at the OpenSSH client. OpenSSH, or more simply, SSH, is the closest thing to a default or standard remote management solution that we have when it comes to Linux. And it's actually a very important thing to learn. Anytime you spin up a Linux server, then SSH is going to be the standard way of connecting to that server to issue commands on that server. And using SSH, you'll actually be able to perform any command that your user account normally has access to, just as if you were standing there right in front of that particular instance, but you can connect to that server from a remote location, which is one of the reasons why SSH is so powerful. Now, there's actually quite a few videos regarding OpenSSH on this channel. And my intent with this video is not to repeat the things that I went over in those videos, but most of those are more advanced. This one is going to be for those of you that are just starting out and you want to find out how to use SSH to connect to a server to manage it. Now, before we get into that, though, I do need to take a moment to mention the sponsor for today's video, Linode. Linode is a cloud server provider with a focus on Linux. You could use their platform to spin up your very own Linux server in just minutes. If you don't already have an account yet, you could sign up with Linode using the URL that you see on the screen right now. And that URL will get you $100 in free credit towards your new account. And that credit is good for up to 60 days. And by using that URL to sign up with Linode, you're also supporting Learn Linux TV by telling Linode that you heard about them through this channel. And what do you do right after you spin up a new Linux server? Well, you connect to that server via SSH to set it up. So Linode's platform is a great way to test out foundational concepts to enhance your learning, such as SSH, which we're going to be covering in this video. But regardless, if you don't have your very own Linux server as of yet, it's a great way to follow along and learn with the lessons on this channel. And this video is one of many examples of that. And who knows, after you connect to your new Linode server via SSH, maybe you'll work through the process of creating something like a Next Cloud Server, something that I went over in another video. And that's just one of countless projects that work well on Linode's platform. You can set up a blog, a standard website. Basically, whatever you want to build with your Linux server on Linode's platform, the only limit is your imagination. So thanks yet again to Linode for sponsoring this video, as they've done for many others on this channel. I really appreciate it. Now, I'm excited to show you guys how to connect to a Linux server via SSH. So let's go ahead and dive right in. [SOUND] For this particular tutorial, what you'll need is a Linux server to connect to. It really doesn't matter where that server is, so long as you have access to it. I'm going to use Linode as the example here, but nothing that I'm going to show you in this video is specific to Linode, because well, OpenSSH itself isn't specific to Linode. If you don't already have a Linux server set up, you can support Learn Linux TV by checking out Linode and spinning up a server on their platform. Or you can simply use any Linux installation that you might already have. In my case here, as you can see, I have two servers that I set up, Ubuntu 1 and Ubuntu 2. So I'll be showing you examples of connecting to those particular servers. Anyway, once you have a Linux server set up, you're going to need its IP address. Most cloud providers out there and virtualization platforms will give you the IP address that's associated with your instance. In my case, I have an IP address that ends in 174. And another that ends in 169. So we have a Linux server or two. So what can we do to connect to those servers? How exactly does OpenSSH work? Well, SSH actually has two components. It has the client component and the server component. The client component is what you actually use to connect to a Linux server. And the server component is how that server actually listens for connections and allows you to connect in the first place. In this video, we'll be focusing exclusively on the SSH client. But I wanted to at least make you guys aware, if you didn't already know, that there's two components for SSH, the server and the client. Okay, so we're going to need an SSH client in order to connect to a server. But how do we go about getting an SSH client? Well, in most cases, you probably already have an SSH client on your system and you might not even be aware of it. For example, when it comes to Mac and Linux distributions, you'll have an SSH client by default. It's already there. There's nothing that you have to do. You simply open up a terminal on your Mac or your Linux workstation and you have an SSH client, you're good to go. But at this point, I'm going to assume that you either have a Windows system with WSL, a Linux distribution, or possibly a Mac, or maybe something else. But you're going to need the SSH client and for most of you, that should already be taken care of. So here I have a terminal open on my computer. And if I type which in the SSH that works on Linux and Mac, if you run that command, it'll give you output if the SSH command is available. In my case, it is, which means I have the SSH client installed. Now you shouldn't need to do anything. You should already have it. If you don't, then you could just use your package manager or however you normally get software on your operating system to pull down the SSH client. Now switching back to my Linux dashboard, we have two IP addresses here, one for each of the two instances. So what I'm going to do is just go ahead and copy this IP address and I'll give you an example right now of using SSH to connect to that particular server. And the way SSH works is we'll type SSH and then space. Then we'll type the username on the server that we want to connect to. So whatever your username is on that particular server, we'll type that in right here. So on my servers, my username there is J, so I type that in. Type the at symbol and then we'll type the IP address or the domain name if your server has a domain name. It could be either the IP address or the domain name, doesn't really matter. But you need at least one. So I'll paste in the IP address right here and there it is. So I'll press Enter and that should start the connection. If you see this prompt right here, if it's the first time you've ever connected to that server, then it's just verifying that you actually want to connect to the server. It shouldn't actually come up again unless there's a problem or something like that. So what we could do is just type yes and then press Enter. Next we'll type the password. And after we enter our password, we should be connected to our server. In my case, I'm connected to the first Ubuntu server that I set up for today's tutorial on Linode. Anyway, now that I'm connected to my first Linux instance, what I could do is run any command that I have access to run on the system. So for example, sudo apt update. Want to update the package repository index. This is a command for Ubuntu and Debian systems specifically. But you could run whatever command you normally run on your Linux servers. So I'll just press Enter, type in the password. And as you can see, it works just like I'm right in front of a console, a physical console to that server. But instead, I'm connecting to this server from the comfort of my home office. And now that I've done that, for example, I could go ahead and install updates. I'm just simulating some things that you might want to do on a Linux server. You don't have to follow along with this. But installing updates is a really good thing to do. So I'll run sudo apt dist upgrade. And that should get that going. So we have some updates. So I'm managing my Linux server from my home office. How cool is this? I'm just firing off commands as if I have a physical keyboard right in front of the server. But again, I'm running all these commands from my home studio. And this server in particular is actually in Canada. If you're curious, I'm in Michigan. But as far as I know, the Toronto data center with one out is the closest one. So I always pick that. And I was able to connect to that server via SSH as you just saw. So as an aside, this particular message right here, I could just simply press Enter to skip that. I'll press Enter again. I could cover those things in a different video. We're basically focusing on SSH today. And anyway, you just saw me connect to the server and run commands. So we know that it's working. SSH is working just fine. And when I'm done with my session, I could simply type the word exit just like this. I'll press Enter. And then you can see that my command prompt changed. I'm back to my local command prompt. So now I'm disconnected from the server. So next, I'd like to give you another example. But this one is going to be a bit of a scenario. I'm going to connect to a server, the second server that you saw on my list of Linode instances. But spoiler alert, this one's going to fail. I'll show you exactly what I mean. So I'll type SSH and then my username again. And then at, I'll paste in the IP address of the second instance, which I've done. And I'll press Enter. Let's watch it fail. It's telling me connection refused. That's odd. Well, actually, I knew that would happen. But you may or may not know what that means. But what I've done is I've actually set up the SSH server on that particular instance to listen on a different port. By default, port 22 is the port that's used. And if you don't specify a port, in this case, I didn't. I just simply typed SSH, J, at, and then the IP address. I didn't tell it to use a different port. So because this server is actually not listening on the default port of 22, then it's actually going to be refused because there's nothing listening on port 22. That makes sense. Now don't worry too much about how to change the port on the server end. I have other videos that goes over that. So what I'm going to do is show you guys how to connect to a server via a different port. Maybe you have a server that you're given access to by a client. And maybe that client uses a different port for the SSH service. It happens. So what we're going to do is recall the command that we just used. I just pressed the up arrow here. And we're going to add another option, dash P. And that's going to allow us to specify a port. And specifically, it's port 2222. It looks like I have an extra space there. Anyway, what I've done is I've used the dash P option, which tells the SSH client that I would like to use a different port for the connection. In this case, the server that I want to connect to is listening on port 2222 for SSH, not the normal port 22. And this command is going to allow me to get into that server. Let's see if it works. So again, I'll confirm the connection by typing yes, I'll press enter. I'll type in my super secret password. And now I'm into the second server, just like that. So at this point, you might be wondering, why would anyone want to change the port that SSH listens on? Is there any value in doing that? Well, there might be. There's not much when it comes to value, there is a little bit of a benefit that you get. When it comes to security, people are really trying SSH a lot. I mean, when it comes to threat actors out there that want to break into a Linux server, I could promise you that SSH is always going to be the very first thing that they try. And that makes sense because well, SSH is very useful. It allows us to manage Linux servers remotely from our home office. But when it comes to outside threat actors, that's especially attractive because they also like to manage Linux servers from the comfort of their home office. It's just that the difference between us and them is that they're connecting to servers that they don't legally have access to or weren't granted permission to access. They want to break into something and we're just doing our job. So what some people might do, some Linux administrators, is that they might change the SSH port to confuse threat actors a bit, but it doesn't add that much security. But that's basically why some Linux administrators go and change the port. Could be something that you might want to consider doing. And if so, again, I have videos that cover SSH and all the related topics, but I just wanted to mention that this is something that you might run into. So anyway, this is the command right here that we've used most recently to connect to the second server, the server that I had listen on a different port for SSH. So as you can see, I was able to connect to that via this command right here. But one thing that I want to show you is that we could simplify this a little bit. For example, I could actually remove JAt, so I could remove the username, essentially, from the command. And that command would be very short if I wasn't designating the port. If the port was on the standard port of port 22, then the command would be this simple. And that actually is the shorter way of connecting to a server. Again, if you don't have to specify a port, I didn't specify the username either. And that's what I wanted to show you here, because if you don't specify the user and then the at symbol with the SSH command, like you saw me do with every example so far, then it's going to assume that the username on the target server is the same username as your local user account. And if that's true, you don't have to type the username. If the username is the same on both ends, then you can omit that because, well, SSH makes the assumption that the username is the same on the target unless you tell it otherwise. And so far, by typing the username at and then the IP address, we've been telling the SSH client that we want to use a different username. But the username was the same, so that was a little redundant. So as you can see, we can simplify that a little bit. And we can then use the username if we need to use it. But if the username is not different, well, we could just omit that altogether. And we'll just have fewer characters to type. But anyway, that was basically about it. Anyway, that's about it. I just showed you guys how to use the SSH client on your Linux system, Mac, or whatever you happen to have locally to connect to a Linux server remotely to manage it. And that's a very great use case for SSH. It's just so helpful when it comes to actually managing Linux servers to be able to connect to that server from wherever we happen to be. Now, if this video was helpful, then please be sure to click that like button that lets YouTube know that you enjoyed this video and maybe other people might want to enjoy it as well. I also have other episodes coming in this series, so be sure to subscribe so that way you'll be the first to see those episodes as soon as they're released. In the meantime, though, thank you so much for watching. I really appreciate it. And I'll see you in the next video.
Info
Channel: Learn Linux TV
Views: 32,679
Rating: undefined out of 5
Keywords: Linux, gnu/linux, LearnLinuxTV, Learn Linux TV, LearnLinux.TV, Learn Linux, Linux Training, Linux Tutorials, Linux SSH, ssh client, ssh command, linux for beginners 2022, linux for beginners 2023, linux commands, learn linux ubuntu for beginners, learn linux ubuntu, learn linux tv ssh, linux tutorial playlist, linux for beginners, linux command line, linux server, devops, cloud computing, linux terminal, operating system, how to, linux command line for beginners
Id: kjFz7Lp8Qjk
Channel Id: undefined
Length: 15min 54sec (954 seconds)
Published: Tue Feb 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.