 Hey everyone, how are you doing it? Welcome back to some more Python programming videos and tutorials in this small little series We're gonna be looking at how we can kind of automate SSH within Python now for those of you that don't know about SSH It is a secure shell that kind of gives you a little remote access Kind of connectivity to another computer somewhere else in the world I'm not gonna go into a whole lot of depth about it and that was probably a pretty terrible explanation But it's something you can definitely look up online But I want to go into the series with the kind of expectation and understand you guys know what SSH is and how you can use it So for this tutorial series, I'm pretty much going to be using SSH with the bandits From the bandit challenge from over the wire org So that's kind of what I'm going to be using as my SSH target So I'm gonna be using the bandit zero user and that's logging in with that user with bandit zero So that should be easy enough hopefully to follow and it's a good kind of example to use as an SSH target Okay, so the actual point of this video is to be get into a new module in Python called PX SSH and That is actually part of the P expect module or at least kind of library or I don't know Thing in in Python, so you probably saw that come up as one of the like first Results in Google So P expect or pex-pect. I don't honestly know what you want to call it It pretty much Allows you as the Python programmer allows you to use Python to control other applications by Expecting what they will do and how they will work it pretty much uses regular expressions I think to kind of look through the output of other commands and other programs that you're using and then allows you to manipulate it and send Stuff to it from that so again, that's just kind of my understanding so far. I could be wrong I'm still learning about this thing too, but hey The description here says P expect or pex-pect can be used for automating interactive applications like SSH FTP password telnet and other stuff It can pretty much be used to automate a setup script for duplicating software packages and other services Etc. Etc. Etc. So it's kind of cool pretty much I'll go into at least a small little API overview to show you how it kind of works in code But we're gonna be using actually the PX SSH module rather than pex P expect For the time being but yeah, like it says you can give it a Program or something to run like a command and then you would expect what kind of output you would normally get from it and Then kind of work with it and play with it from that So okay, I guess that's enough talking about pex-pect and P expect now Let's actually get into PX SSH, but like I said, it's part of the pex-pect module So we're going to install that if you guys don't know how to install it already On Linux or for Ubuntu and Debian that I'm on I'm going to install with sudo apket install Python Paxpect should go ahead install that pretty okay, and now I can fire up idle My Python interpreter. I'll bring this down so you guys can see it and I should be able to import PX SSH Without a problem. Cool. That works just fine for us So now the stuff that I want to teach and show you guys along all a part of PX SSH Everything that we're going to be doing interacting with SSH and the secure shell connection takes part in PX SSH's object It has a specific sort of session object that you create and then manage everything from so you can create that with PX SSH dot and there's a PX SSH object that you're gonna be working with there was another exception Of course that that's how you can learn more about the errors and things that go wrong with the code But for right now we're just going to go with the object and like I said here you just create this and you should be good I'm not going to go into a whole lot more of a description of what all this all does right now We're just going to go ahead and create it so I want to sort as an object So I'm going to say s equals this awesome and that works fine for us and now we have our PX SSH object so the command to actually connect to a server or log in somewhere is easily enough Log in and you can see this take some arguments like the server the username and the password And there's a bunch of other stuff and optional arguments that I'll get into later But for now, let's just go ahead and log in Pretty simple. We know that our server is bandit.labs.overthewire.org username is bandit0 and They describe on their website that the password for this user is still bandit0 So let's go ahead and connect to this it'll take a few moments and it should return true Excellent when we've connected so easily enough The log in function is to log in and of course to log out function is to log out You can see this sends exit to the remote shell If there are any stop jobs and this automatically sends exit twice and just gets out of there So it doesn't return anything for us But now let's try and connect again because I do want to actually play around with this stuff and do more with our shell so I'll alt P to get back up to the command that we ran previously and I'll hit enter Whoa, and why am I getting an error, right? It should be easy enough just connect, right? So Assert self.pid is none the PID member must be set to none. Okay, so the PID member must be set to none Okay I'm gonna use that as a segue and kind of a transition to get into the next tutorial We're gonna be looking at more of the options and other things you can do with this PX SSH object and kind of session manager and controller object But for now this video I want to show you what it is what it's a part of how you can get it how you can install it and simple ways to log in and log out and We'll get into new stuff in the next coming tutorial. So thank you guys for watching I know this was very very simple and we'll get into cool stuff very very soon. See you soon