How to Generate GitHub SSH Keys

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you need to SSH into GitHub maybe you don't know where to start maybe you need some help generating those GitHub SSH Keys maybe you just need to be shown how to set up those SSH keys in GitHub or maybe you hit that pesky permission denied public key error and you you'd like me to show you how to get around it well don't worry whatever the situation is I'm going to get you connecting to GitHub over ssh in no time and when you do connect to GitHub over SSH I've got two requests one when you speak about me say nice things and two check out my git and GitHub tutorial that I recently published on YouTube it's two hours long it's going to make you very very very dangerous when it comes to these git and GitHub tools now working with SSH if you want to SSH into GitHub the first thing you need is a pair of SSH keys and those SSH keys can be found under your home directory on Windows or even a into um I'm logged in as a usern named owner on my Windows machine here and you can see in that owner directory I do not have a folder called SSH the SSH folder is where git looks for your public and private keys to do that handshake with GitHub on the server um and if you don't have that SSH folder well you don't have SSH keys on your machine you're going to need to generate them so step one if you want an SSH into GitHub is generating those SSH keys so how do you do that well all you have to do is open up Powershell now I will say that uh you can run this exact same command inside terminal on Linux auntu and the command is this it's hey please um would you please generate an SSH key for me ssh-key gen there's one option that you'll want to use I always like to use the Ursa Keys also affectionally known as RSA Keys um and then it's always good to put a little comment in there I always like to throw in my Twitter handle at Cameron M cnz just to remind everybody to go follow me on Twitter and say hello maybe even share this tutorial but uh uh sometimes you put your email address in there's just something that identifies you inside the public key that gets created but that's it that's all you have to do now I'm gonna click the enter button here I'm gonna get asked a couple of questions first so it's going to say okay we're going to generate these Keys um where do you want to save them notice that the folder here is as I mentioned before the users home directory. SSH don't get funny here don't overthink this and say you know there's a better place for these SSH keys that that is where git is going to go hunting for your private key to do the handshake when the server provides the public key so don't mess around there I'm just going to click enter and accept the defaults do you want to secure this key I'm not going to you can if you want to but somebody gains access to my machine I probably got bigger issues so I'm just going to click enter there twice and boom notice what happened in that home directory of mine there's a new folder in there it's called SSH and that wasn't there before and that's where my public and private keys are stored so I'm going to go in those in a second but first i'm just going to observe and enjoy this beautiful piece of Jackson poic art that has been displayed to me looks good thank you very much makes my day just to see those things okay the SSH folder you'll notice that we've got two files in here one file is your public key the other file is your private key you put your public key up on GitHub you keep your private key private um and then when you do SSH that public key gets compared to the private key and if everything matches well then you're clone your fetches your pushes your pulls they'll all go swimmingly but I do need to take that public key and move it up to GitHub so I'm going to open this up I'm going to open this up with my favorite text editor called notepad++ and all of a sudden it says Hey here is that public key that's the one you generated how do I know that's the one that I generated oh look at that my Twitter handle is in there I don't think that's anybody else's public SSH key so open that up take a look at the key copy that key because you need to get that up to GitHub so I'm going to open up my GitHub account here I am right there over on GitHub that's me fa and uh I'm going to go into the settings here so I click on my uh profile picture and then I'm going to come down here to settings click on settings and then over on that leftand side you'll see a a friendly little link for SSH and gpg keys and that's exactly where we want to go and it says hey do you have any SSH keys and I'm like yeah yeah I do says okay well add your new SSH key here and I'm like yeah okay I will and so I paste the key in here and I'll do the GitHub SSH example tutorial I guess looks good as the name title of the key really doesn't matter just add that SSH key okay so now you've got your SSH key your public key up on GitHub and you've got your private SSH key on your local machine now you should be able to do a handshake and clone over SSL SSH between your local machine and the server so let's do that next I'm going to go back to the landing page of my repository this one's called learn get fast just in case you were looking for it um once I'm here I'm going to click on that repositories Tab and I've got a repository called salmon just actually doing a little tutorial on Upstream branches in git nothing goes up stream like a salmon does so I'm going to click on that project right there and there's this beautiful green button and this beautiful green button has a couple of links that will uniquely identify this repository one of them is an https link but https is for losers we want to use SSH here so I click on that SSH link then I click on that copy to copy the SSH UR URL is that called an SSH URL looks like a URL um so I copy that and now I can go on to my local machine and clone this repository so let's head over here Mosey on into this folder called repos I'm going to rightclick here and select open git bash here now if you don't have an open git bash here now uh you may not have G installed so you do have to have get installed in order to uh do a clone to the server I've actually got some how to install get tutorials up on my YouTube channel um but all I have to do now is say get let's clone paste in that SSH URL and I'm going to click enter I'm going to keep my eye on the prize over on the right hand side to to watch the the salmon folder get created but I don't know I might be challenged here let's see what happens the first time we try to SSH into GitHub so it says oh look at this the auth authenticity of host GitHub can't be established H looks like some shady website right uh it's a Microsoft website isn't it well that doesn't mean it's shady I don't know what is um of of course we trust them are you sure you want to continue connecting type in yes don't click enter you got to type in yes I trust Microsoft and GitHub with all of my data so I click yes notice that folder's been created on the right hand side salmon is over there says we've permanently added GitHub to the list of known hosts and boom all of a sudden I have cloned down to my local file system and if you don't believe me I can move over into this salmon folder and you can see alpha bravo charlie and dvo and that matches the files over there on my server alpha bravo charlie and dvo boom I have connect I have have successfully connected to GitHub using SSH and done an SSH clone from GitHub as well so things are going swimmingly by the way I mentioned that uh Microsoft owns GitHub they bought them for $9 billion so if you ever see a business opportunity where you can take free open soft open source software put in the cloud and charge people for it that's a good business model okay so now I've cloned from GitHub using SSH uh there's a couple of other things that uh I need to do as well just to prove that SSH is working I want to do maybe a pull maybe a fetch maybe a push as well so the way that git and GitHub works the the whole ying-yang of git is this so first when you work with Git you'll have a remote repository from which you'll clone and that brings down the repository from the server onto to your local file system after you do a clone you then add files and then you add them to the staging index you do a get add that stages the files tells git which files you want to include the next commit and then you do a git commit and then after that git commit has taken a snapshot of the state of your files you can move that up to GitHub by doing a push you can actually do that all in one step with a get commit Das a command and then a push but you get the idea um if people make changes up to the server and you want to bring those changes down locally then you pull so the first time you clone the second time you pull every subsequent time you pull from the server and optionally if uh instead of doing a pull you want to do a Fetch and then a merge that suits your fancy you can do that as well but why don't we do that why don't we prove that out and just see how this works here so I'm going to go on to my local file system I'm going to create a new text document I'm going to call it Echo do txt so a new file has been created I'll say open git bash here I'll type in git status and says to me hey there's an untracked file here a file that hasn't been added to get staging index and hey why don't I stage it then so I'll say get add echo. txt and now that stages the file so that when I do a commit it'll be included in the next commit I can go get status again and it says okay there's one change to be committed if you do a commit that new file is echo. txt I do what I'm told I'm not afraid of commitment despite what my friends might say I'm going to do a commit right here and I'll say get commit DM for a get commit message and I'll say my SSH GitHub example commit it's a long commit but I do my commit and now I've created a get commit history on my local file system but it's not shared with the server so if you come over here and you take a look at what's on the server even if I click refresh well you'll notice that I've got dvo up on the server is the last file that was created there but I've got echo on my local file system I want to move Echo to the server that means doing an SSH push and there's nothing special about an SSH push you just say get push and since SSH and GitHub has already been configured it does the push to the server and I come back here and I can see that hey where it's not I'm just joking do a refresh and there you go boom Echo is now up on the server so initially we do a clone um then you add files edit files commit them and do a push to the server there's also the opposite right there's also the fact that maybe somebody can add a file in the server maybe one of your co-workers one of your Cod developers pushes a file to the server and you might want want that so let's simulate that just by creating a new file here and so we've got Echo what did I call create fred. txt hello Fred commit those changes on the server and now I'm in this crazy situation where the server actually has more files than my client machine right I've got Fred over there in the server I don't have Fred on the client so how do you do that well once again you can say open get bash here I want those files on my local file system so I say get pull and when I click pull keep your eye on the prize boom fred. txt comes down so initially I did a SSH clone then I do an SSH push now I've done an SSH pull by the way there's also something called a fetch which uh some people often get uh confused on um when you do a poll it actually takes the files from the server and puts them right on your local file system so you saw Fred go right to the file system there sometimes you might be working on files sometimes you might just want to pull from the server and and find out information about what's happening on the server like are there more commits or are do you have more commits than the server um you know is the is your head certain number of commits ahead or behind um and but you don't actually want to overwrite the files in your file system and you can do that with a fetch so I'm just going to show you that here uh may as well do an SSH fetch here I'm going to add a new file to the server so add file what happens after F in the golf. txt I love golf commit those changes so right now you can see that up on the server we've got uh golf Where's golf how how come I don't have golf there little refresh we got golf there but I don't have that on the client side um so the server is has been updated now right now if I do a get status Command right now it says that your branch is up to date with origin main origin main is the server but in fact it's not up to date right we both know that the server's got an extra commit on it so if you want to find out what's going on with the server um but not necessarily update the files that you're working on you can always do a get fetch and as I do a get fetch over SSH to GitHub in this case what will happen is we'll get updated about the remote server about G updated about GitHub but the changes won't come down onto my file system so notice I don't have golf on my file system but if uh I do this I say get status it says your branch is behind origin main by one commit so the server is one commit ahead of you we're behind the server so the fetch has brought information from the server down to my local machine but not overwritten things now you can always say a get merge origin Main and that'll now Force the changes that were pulled down from the main branch on GitHub origin right here just means GitHub um click that and boom you can actually see golf. txt over there as we do the SSH Fetch and then the the merge back into the the client system so there you go now I think that is pretty much all of the operations that you can do with SSH to GitHub so I don't know I hope that was elucidat ter um yeah I think there you go you know everything you need to know about SS and GitHub now by the way I don't think I introduced myself earlier my name is Cameron McKenzie I'm the editor and chief over at the servers side.com and I have to be one of the world's uh biggest git Advocates and uh over on the server side we've got all sorts of great tutorials about git GitHub devops Java python agile scrum you name it so head over there see what we're up to um if you're interested in my personal Antics uh you can always follow me on Twitter uh my handle is @ camon mcnc and you know I'd really love to to hear from you if you enjoyed this video and if it it helped you out so share the video and tag me on Twitter and say hello or find me on LinkedIn uh as well and one other thing I would suggest um I do have a newsletter the link to the newsletter is in the description we talk all about devops tools like git and Jenkins and GitHub actions and all of those things um but uh we also talk a little bit about what's going on in the software development industry and you may not know but there's a brand new programming language about to come out it's called Mojo and it's poised to completely replace python along with another a number of other languages in the AI and ml space and if you don't get up to speed on this new Mojo programming language you are seriously going to fall behind so we're talking a lot about like that along along with a lot of uh teaching and training videos about Mojo and the AI space so as I said please uh take a look at the the link to the newsletter and sign up and keep up to date on what's going on there by the way I do also have a a couple of books so I wrote the book Pickering is Springfield All About The Simpsons and uh also hibernate me easy and I'm also working with a young freelancer as well you can see the book in the background Darcy declute scrumptuous on Twitter and uh she wrote the scrum Master certification guide a number of people have read that book and scored 100% on the scrum Master certification exam so if you're agile or you know somebody else that's uh interested in scrum certification uh get them that book and there you go that's about it um the last thing I would say is that if you're watching this video on YouTube um you should subscribe on YouTube
Info
Channel: Cameron McKenzie
Views: 8,346
Rating: undefined out of 5
Keywords: cameronmcnz, theserverside, java, jakarta, jakartaee, git, github, gitlab, dvcs, versioncontrol, tortoisegit, gitgui, atlassian, bitbucket, linux, azure, devops, devopstools, gitops, gitopstools, azuredevops
Id: Z-HNfaYZ4Dc
Channel Id: undefined
Length: 19min 15sec (1155 seconds)
Published: Wed Jan 31 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.