How to configure GitHub SSH CORRECTLY

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there and welcome back to the channel so in this video we will create an SSH configuration for GitHub but we will do this the right way and that is without compromising on security or convenience so by the end of the video you have a really good and well polished configuration going on for you let's go so I want to clone this project over here qmk copy the SSH HL jump into the terminal let's try to get clone and paste the SSH URL that we just copied and we get an error permission denied good SSH is working as it should to set up SSH we need two files one containing a private key and one contain a public key this is what is called a key pair these keys are generated using beautiful cryptographic algorithms what you need to know about this is that you will give your public key to GitHub so GitHub can encrypt everything they sends to you and the only person who can decrypt it is the one that has the private key hopefully only you so type SSH key gen which you already have installed probably and then- T ed25519 to create a pair of keys it ask for a location for our key files keep the default which is the SSH directory in your home directory and a passphrase though you are allowed to have an empty passphrase I definitely recommend you to create one there now you have a pair of keys one called ID underline ed2 5 59. Pub which is our public key and one simply called ID underline ed25519 without anything afterwards which is your private key and this file you should keep safe another thing is that is DT argument that we pass to SSH key gen Mak sure that he uses the ed25519 cryptographic algorithm to generate the key the default algorithm is RSA which is good nothing wrong with it but this new algorithm ed25519 is faster and more secure so why not use it now open the public key file the one with the pub extension make sure that that's the one and copy it contents to the clipboard and now we go back to GitHub and click on your face in the top right corner go to settings SSH and gpg keys add a new key give it a title and paste the key in there at this point things should just magically start working so back in the terminal let's try get clone again and insert the P phrase and boom it works we got the repository clone locally but check this out let's remove it so rm-rf qmk and let's clone it again yeah annoying so every time you want to connect with GitHub you need to type your passphrase again and that's why many developers do the wrong thing and avoid P phrases Al together but we're better than that let's fix this the right way without compromising Ison on security enter SSH agent so the SSH agent is a program that caches your unlocked private keys so you don't need to type a passphrase every time great now the SSH agent is wonderful but it can get a little bit finicky so hold with me for a second okay now let's see if it's running already which I really hope for your mental sanity that it is so to check if it's running type this Echo space dollar sign SS H underline o under underline sock if you get nothing your agent is not running yet which you should but if not we we can start it and to start it just type this eval space dollar sign open par s sh- agent close PRS enter and it should start running out the correct way some people put this in their Basher C file which is a bad idea because you would start a new agent with every new shell which makes absolutely no sense I don't know why people do that having in your dot profile file makes a little bit more sense and things should work a little bit more reasonably but Mac OS as far as I know is the only OS that got this 100% correctly Apple added a patch to open SSH itself to allow SSH agent to be socket activated and started on Demand by launch D in my opinion this patch should be brought to the main branch of op SSH so systemd and other init systems could also use it is the only reasonable way to handle this otherwise it's messy okay rent over SSH agent is now running now let's add our key to the agent so SSH add and the location of the key type the passphrase one last time and now we can clone our repository without typing the passphrase and as long as the agent is running we will be able to connect to GitHub without ever having to type the pass phrase again job done security and convenience at the same time that that was a mouthful now that we've gone through all this trouble uh I know it was quite a lot but now we have the knowledge necessary to massively simplify all of this and we do this with configuration files okay so let's create an SSH configuration that takes care of everything that we want open or create a file called config in your SSH directory in your home directory and let's add a configuration for github.com let's set add keys to agent to yes so we don't have to call SSH add to add the keys to the agent now let's add user git to simplify the URL we don't need this giit at github.com anymore just github.com is enough and to simplify this even more let's rename this configuration here to just say GitHub you could have anything but let's just use GitHub and say that the host is github.com so now it's enough to type GitHub colon userrepository to refer to a repository no need to go to GitHub anymore and copy the SSH hrl I bet you could impress someone looking over your shoulder and just watching you typ in away GitHub colon repositor boom cloned it's like well how did you know that I don't know cool now you can clone whatever repository you want as long as you know the user and the reposit name usually your own repositories you would know those things all right there are many more configurations that you could use for example identity file and identities only would allow you to change the name of the key in case you end up with a lot of keys but this is enough to get you started this is a solid little configuration that we got going on here and you can expand upon it you will notice that no matter what you want to say say you have a configuration for you now like And subscribe this video and leave a comment letting me know if if you change the way that you use SSH after watching this video or telling me how SSH agent is messing with you now go read The Man pages and that's it for me today hey on
Info
Channel: Lucas Viana
Views: 1,335
Rating: undefined out of 5
Keywords:
Id: hK2DQ6kd-PM
Channel Id: undefined
Length: 7min 15sec (435 seconds)
Published: Sun Mar 03 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.