 Hey everyone and welcome back to another Python programming tutorial and video in the in the series that we're in currently We've been checking out this module PX SSH And that allowed us to kind of manipulate SSH or the secure shell within Python to connect the servers and to run commands And that's sort of really cool stuff So in the last video just to get things started we created this new object that kind of acted as our SSH manager or Controller and to review we used that to go ahead and log in to a server, right? We were using a over-the-wires a bandits war games account and That's really what we were using as our example for an SSH thing to log into So their user was bandit zero and the password was also bandit zero So once we were able to log in it returned true for us, which means that we got in successfully when we tried to log out We were able to log out of course, but when we tried to log back in It gives us this error and we were like what what's going on now? I wanted to use this as a segue and a transition to talk about the options and Variables and other attributes and properties that come with this s object or our SSH kind of controller and object manager So it's telling us here that the self dot PID or self being of course s the object that we just created It's a variable PID. It's got to be set to none for us to be able to log in So here's an interesting thing once we create this object obviously that creates the s dot PID Variable and property once we log in that's going to be set to something other than none When we log in it has to equal none because I mean it was just created, right? Once we log into the server. We've got a process ID for our SSH program and now it's no longer none Once we log out for some reason whatever reason probably because we can only have one session one secure shell session With our object at a time But whatever the case may be it's not reset to none. We could try and reset it to none That might work for us and then we could log in again I've had some trouble with that so I'm not going to take that route But of course another object another option is to just Re-initialize the object Right, so now when I check out self dot PID. I'm not going to be returned to me thing because it's equal to none So I can go ahead and log in right Without a problem sweet. Okay, so that was one of the simple Options that I wanted to show you with our s object and our SSH kind of controller You'll notice if you just type in your dot selector and then check out You know control space to kind of autocomplete you can see this big long list of all the kind of cool stuff that this module and Object can offer you so I Want to go through some of those Now before I get into a little bit more though I do want to show off how the login function works in PX SSH so I guess I'm gonna put my money where the mouth is and log out and Log in again after I re-initialize the object So I want to show you how this login function has more Options and arguments to it, so I'll bring this down here and you'll notice of course the server and username are mandatory Arguments the password is optional because you could very well have a user that does not have a password The terminal type. There's an original prompt and that's kind of interesting I want to know what that original prompt is all about Log in timeouts ports None by default is probably going to reset you to 22, but of course you can supply what port you want to go to This is H key. They're not it's quiet and all this stuff So the description here it gives is of course This logs the user into the given server and it uses the original prompt variable and the argument to try and find The prompt right after login when it finds the prompt it immediately retries to reset the prompt to something more easily matched What does that mean right? So the default original prompt is very optimistic and it's easily fooled it's more reliable to try and match the original and I Guess it's cut off there So it's interesting those those are backslash Control backslash that I do inside the function So you actually get a little bit more of the description and the tooltip that comes from the help and the Documentation of the module you're not gonna be able to find a whole lot of documentation for PX SSH online, but we can of course find it in the module itself So if I pass in s.login the function into this help function We'll be able to see everything that it gives us and let's go through and read a little bit more of that description here It says it's more liable to try and match the original prompt as exactly as possible To prevent false matches by server strings such as the message of the day on many systems You can disable the message of the day on the remote server by creating a zero-life file called hush login If a prompt cannot be found that it does not necessarily mean the login failed in case of this a timeout It's when using it for a prompt. We assume that the original prompt was so weird We were not able to match it So we use a few tricks to guess where we've reached the prompt and then we just hope for the best and blindly try and reset The prompt is something more unique if that fails then login will raise an exception and give us the error Okay, so that's that's kind of weird, right? There's a there's a lot of stuff going on there, but notice that the original prompt It's it's regular expressions this Hashtag or this pound symbol and this dollar sign typically represent the root user when you log into a unique system or a regular user When you log into a unique system a pound being root and the dollar sign being any end user This these braces represent regular expressions anything in this set so What it does like it says is it tries to match this and then of course it'll reset it to something a little bit more easily matched but like it says this is very optimistic it may not be the prompt on your server or the thing that you're trying to Connect to so it says it's more liable to try and match the original prompt as exactly as possible Now if you're trying to log into a server you've never been on before Obviously, this is going to be hard to do But keep in mind this is all about P expect Python Expecting how the program is going to work you as the programmer kind of already have a foresight as to how that's gonna It's it's going to work for you like I've of course already logged into a bandit zero at bandit.labs.overthewire.org Before so I know SSH my bad I already know what it's what the prompts going to be and how it's going to interact it and work with me so But that's what it's saying you're gonna have to expect it just like the P expect module works Here's an interesting thing. What if we try and change here? I'll log out or I'll reset the object and then try and log back in if we try and change the original prompt to equal a new set something like a period here If I try and log in Ho It kind of throws up. It doesn't exactly know what to do now. You'll notice There is no period in the prompt that we would have seen and that's kind of what's giving us this this vomit here Why it's not working and of course it is looking through it with regular expressions Okay, so that's something else that I wanted to show you That original prompt is helpful. It can also it can be a blessing, but it can also be a curse So here's something else that I wanted to show you. I'll reset the object and then try and log in With something incorrect like let's say I had the Wrong password So, I mean it'll try and log in and you'll notice that a GUI pops up this graphic user interface Oh, I can't actually show you this. Why can't I show you that? Okay? I wish you would have been able to see that open SSH It's dialogue box had popped up asking for what the password could be but it tells us this password is refused so that's gonna have that functionality when that works out and Now I also want to show you another is a live property That's does this exist yet? Let's just Reinitialize the object log in with the correct password this time Actually before I do that. I'll show you is alive now if I run it Is alive is false because we haven't connected to anything You'll notice that this description. I'll bring it back up for you It tells us this test if the child process is running or not and it's non-blocking So you pretty immediately be able to tell you whether or not you're alive or you're connected or not if I go ahead and log in If it lets me log in Log in with the correct password We get true hopefully okay cool. So now we can log in and Test if we're alive, and we are alive. I log out Ask if we're alive, and we're not so that's how that works pretty simple stuff, right? Okay, those are for now all the options that I wanted to show you of course if you're interested you can Browse through this long long list of Options that you could have with the s object and the PXS SSH module So definitely give it a browse definitely look through it and of course I would recommend looking through the entire help function on the object itself There you can actually see the documentation of every function and what it does So rather than me kind of helping guide you through them because I'm sure I've missed more than a few So we're still obviously at the basics We still haven't actually sent any commands or done anything with SSH So I hope you guys are bearing with me and kind of get all this bullcrap the early stuff You need to learn first before we get into actually sending commands. So thanks very much guys Hope you enjoyed this. I hope you're learning a little bit more about the PX SSH module If you are maybe like the video, maybe leave me a comment Give me some constructive criticism, and if you're feeling generous, I don't know subscribe, you know, I'd love that Thanks guys. I'll see you soon