Cloning your private github repo in colab with deploy keys

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone so today I'm going to show you how you can import a private GitHub project into Google collab using deploy Keys okay so the reason why you might want to do this is you have some kind of project and you want to use the free compute on colab however this is a protected project and I'm going to show you a way that you can now import your projects without ever having to worry about passwords and for it to still be safe okay so today what we're going to do first going to start by creating a private GitHub project so you could probably skip this if you're pretty familiar with these things we're then going to generate and upload our deploy keys on GitHub and finally we're gonna integrate this uh all to Google collab and even to Google Drive okay so I'll show you essentially we're going to add these keys to Google Drive and we'll be able to fetch them from from our drive to collab and have this be done automatically every time we log in okay so let's get started first things first let's just uh create a project okay so I'm just going to call this my secret project and we're gonna go into this secret project and this is just going to be something really simple so essentially here what we're going to just do is print you know my super secret project and that's it so now if I run this script it just prints you know my super secret project so that's all we want to do so now we're going to go to GitHub and we're going to actually create a new repository and so we're going to create this as a private repository so here we have my secret uh project and we create this as a private repository create Repository so now it gives us all of these things so we're going to use this to actually go ahead and push our project so let's go back here let's just initialize this as a git repo um and now we can add this Commit This files let's say my first Secret commit and now we'll just use uh just this one time you know the command that GitHub gives us so that we can push this up all right so so far essentially all we've done is we can go check out our uh our page here if we refresh this oops so you can see here we have um our first commit and our file so we just have print my super secret project so that's all alright so now let's go to Google Cola okay and if we go to Google collab uh just a brand brand new collab so let's try to actually clone this code so let's just make sure that we cannot clone this code so get cologne I'm going to try to clone this thing and it's going to tell us no we actually don't have no repository rights okay so let's just like first of all I'll just disconnect delete make sure that like this is all completely from scratch okay so now let's try that again so get clone it's going to connect initialize you know and it's going to tell me nope you cannot do this all right obviously it's a secret project so that's a good thing you know you could even try through https and it shouldn't work all right so now let's look at how we can actually go add some uh deploy keys on here okay so if we go to settings you will see here there is a thing called deploy Keys okay so you can see here there are no deploy Keys you can check out our guide on deploy key so we'll open this guide I already had it opened here so we'll close it and it just tells you all uh you know the pros and cons of using deploy keys so look this up but essentially these are the nice things so first of all you don't have to mess around with anything and deploy keys are read only by default so you essentially the bearer of the key Whoever has this can just read this whenever you want and another really nice thing is that you can just essentially revoke these keys at any point okay now be sure to read through all of these things but essentially here are all of the pros and cons and the first thing that we need to do GitHub doesn't actually do this for us is uh set up the actual keys so we're going to generate our own keys so here we're going to open this in a new tab and it's just going to explain to you how to generate a new key so I'm actually going to do this locally and show you how this happens okay so if you type this command here and remove that dollar sign and I'm going to actually just put my email instead so here I'm going to generate a public Key by default it wants to put this into SSH but for this project I'm actually going to put it just in place so I'm going to name it id255 two five five one nine okay so let's be sure we don't have a typo here yeah so this looks good end to the passphrase I'm going to keep it empty keep it empty again and now you can see here I've generated two keys so this is my private key which you should keep safe and this is the public key that actually anyone can see so I'm just going to print the contents of the public key and this is what I am actually going to tell GitHub to upload as my public key okay so I'm going to just copy this go to GitHub and now here we can actually add our deploy key right and here we're going to say Secret you could keep our secret project or whatever okay so um we're not going to allow write access this time around either so we're just going to add this as uh our key and you can see that it's never been used and this is the really nice thing if at any point I think that someone took over my keys I can just delete this okay so now the next thing that we're going to do is we're actually going to upload this to Google Drive so I've created here a folder just called deploy keys and so let's open our finder window here and so I'm going to upload both of these keys to my drive okay so why am I doing this this is because I don't want to have to regenerate these Keys over and over and Google collab is already linked to my drive so essentially by having these two things linked I can now just go to Google collab and I should be able to copy these Keys every time from my drive okay so let's just make sure that I have access to my drive so I think you have to explicitly tell it to connect to Google Drive yeah so I have to mount my drive so connect to Google Drive it's going to take a second all right so now I'm connected to my drive and I can now go and copy these keys so deploy keys right I have to go into my drive and then deploy keys and then here I should have you know my uh well let's just complete this so put both of these keys and we're gonna put them on the SSH folder of this actual machine okay so we're going to copy these things into here so let's run that and now so you can see that I have my keys inside uh inside my machine okay so the next thing now that we need to do is we need to tell my machine that we actually trust GitHub okay so for this I'm just going to copy a code snippet that I uh that I already had um so which you can also copy yourselves as well but essentially this tells my machine you can add GitHub as some kind of thing that you trust okay now if we want to actually test that our connection works just fine okay that GitHub actually is communicating with our server via SSH here we can just do ssh.t git github.com and this should actually see see it actually knows even who I am so it says I've successfully authenticated to this project because it knows about my key and knows about my public key so this is pretty cool and now I can just run this the Clone command again and this should actually clone this project and you can see that I now have access to this project so it clones it under my secret project in fact let's just check it out if I run python my secret project main.pi you can see now it's printed okay so this is really cool but now one thing that's even cooler is uh now that I have all this let's let's disconnect this whole thing but because I've actually saved those keys in my Google Drive okay I don't need to run a password any any time ever again so I can now uh every time I load this collab I'll just make sure that my drive is mounted copy these files over so we're just going to wait here but you essentially add this as a one-liner to your um to your collab and that's it so let's just wait for this thing to mount and I'll show you so oh yeah it can happen sometimes for some reason that you don't have the SSH directory if you don't just create it okay and uh now we just follow these steps again there you go hit clone cloned again and now you see you have my super secret project so now actually I can deploy this project and if at any point I feel like I am not comfortable anymore with these keys well I can manage my keys directly from my repository so I can delete this at any point so you can give this let's say to other developers you can share these keys with people you trust but if for whatever reason at some point you think okay let's remove access to these Keys you're the one in control so you never had to give a password to this repository you never had to give right access to this repository all you had to do was just create this key alright so I hope this helps and uh I'll uh I'll upload this notebook as well so people can use it thanks for watching foreign
Info
Channel: Jeremy Pinto
Views: 3,682
Rating: undefined out of 5
Keywords:
Id: nTCyuVWEjwk
Channel Id: undefined
Length: 10min 47sec (647 seconds)
Published: Mon Nov 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.