Generate GitLab SSH Keys & setup SSH on GitLab

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you want to use SSH when you connect to gitlab and do those Push Pull Fetch and clone operations well I'm here to tell you that it's not too hard to do all you need to do is generate some gitlab SSH Keys set up those gitlab SSH keys in gitlab get the SSH URL for your repository and then just clone using that SSH URL like you would clone any other repository it's really not that difficult and if you give me just a few minutes I am going to get up to speed on SSH and gitlab and get you connected with SSL I'm not going to waste your time the only thing I ask is that when you speak about me you say nice things and maybe even check out my git and gitlab tutorial on YouTube it's two hours long and I'd love for it to get a couple of extra views and a couple of extra likes now if you want to get started with SSH you have to generate some SSH keys and on Windows you do that by open opening up Windows Powershell and in Windows Powershell you just issue the command to generate SSH Keys now you might be wondering hey I'm want auntu well you just open a terminal window on auntu and issue the exact same command these SSH keys are going to be created and they're going to get put in the SSH folder of the user's home directory now I'm logged in as a usern named owner and I've got that home directory open up and as I said it would be the same as home directory on auntu as well and the SSH Keys get put in a folder name SSH ssh isn't that creative um but you'll notice that I don't have that very uncreative named SSH folder on my file system which means I don't have any SSH keys yet so I do need to generate them by the way if you're having problems with your SSH connection maybe uh your existing keys aren't working so maybe back the them up delete them and then use this command to regenerate your SSH keys so if you don't have SSH Keys what's the command to use to generate them yeah just type in ssh-key gen makes a lot of sense uh there's one option I like to do that's the- o and it's the type and I like the Ursa types the RSA types um and I always like to add a comment uh whenever I generate an SSH key and maybe just mail at MC z.com which is my email address and that is the command now before I click enter here I just want to bring your attention over to the right hand side and watch as I click enter a new folder there is going to get created the SSH folder which will contain these gitlab SSH keys I will be prompted for a few questions before that happens so as I click enter it generates those private and public RSA Keys it says where do you want to save these the default is SSH that's where git looks for your SSH keys don't get creative here don't get silly don't put them in some other location that's the default that's where you want them so click enter to accept that it asks for a passphrase if you want to secure this I'm going to be lazy and just click enter to have no passphrase and when we're done boom you can see that SSH folder is created under the users home directory and I'm also given a nice Jackson poock painting over here a nice little piece of random art to make me smile and have a great afternoon now I've got these files created Let's uh go in and take a look at them you'll notice that there's two files a private key and a public key how do you know which one's public well it's the one that ends thep extension I need to take a look at that because I need to tell gitlab about that public key you put your public key on gitlab and then when git tries to connect there's a handshake that takes place and the crypto algorithms that validate the private key against the public key take place and authentication is performed for us but we do need to put that public key up on the server now how do I know this is the public key I generated well you can see right there I got my email address on it who else would put mail at M c n z in on their public key so I'm going to copy that contrl c I'll do it visually rightclick and copy copy this six ways to Sunday and now I need to get that public key up to gitlab so I log into gitlab I bring up gitlab then I bring up this you know I can never find it so you got to click on like your profile here and you click on your profile and then you say edit edit profile and then you got to click up there again and you notice a whole bunch of other options appear so it's kind of like I just don't like the fact that that sidebar disappears I want it there permanently but you'll notice that one of those links that appears is SSH keys and where else are we going to put our SSH keys in gitlab other than where gitlab says put your SSH Keys here so I'm going to click on that um it says hey do you want to add a new SSH key it's like hey how did you know um so I'm going to click the add new key button paste in that SSH key it's got a title got an authentication and signing type everything looks good to me I'll accept the rest of the default and click add key and boom the key is now added now in theory I should be able to clone Push Pull and fetch using SSH with gitlab anytime I do a a command at the command liner in The Bash shell so let's see if that works I've got a project here on my uh in my gitlab account it's called rock paper scissors and so in order to clone and work with uh gitlab repository over SSH um you'll need to gain access to the SSH URL and so you do that by clicking on your project clicking on your repository so again I'll go back to my um user interface here there's my personal project rock paper scissors once I'm in the repository I click on this friendly blue button and one of the options is to clone with SSH I copy that URL so again I'll just show it to you up there that's it there make sure that SSH URL gets copy you know I mean it says clone with SSH then I come down over here onto my file system and I've got a folder called repos I rightclick I say open git bash here with Git bash open I issue the git clone command with that URL I click enter with extreme Vengeance and Prejudice now it says to me whoa whoa uh are you sure you want to do this the authenticity of gitlab can't be established is that some shady Organization no that's not shady that's a great organization are you sure you want to continue connecting of course I do so I type in yes it says we permanently added gitlab to the list of known hosts and then it's going to go up there and it's going to clone that repository and bring all of that code down and if you don't believe me you can just go over here open up the rock paper scissors folder that was just cloned and there's the index and there is the readme file and if I come over here you notice there's the index and the readme file up on the server so I've effectively cloned that gitlab repository with SSH so what's next well um you know when you're working with any you know git based operating system git based SAS tool git based hosting service like gitlab or GitHub or bitbucket the the ying and yang is this you first clone the remote repository then you start adding files editing files and then the files that you want get to track you add to get staging index then you do a commit and then you push those commits back to the server um you can actually do the whole uh adding staging the file then committing Allin one if you use the- a switch with your commit you still have to push um and then that gets your changes up to the server if somebody else makes changes in order to get their changes down to your local machine you do a PLL optionally you can do a Fetch and a merge too but that's the the basic ying and yang of working with Git and gitlab so why don't I come over here and just create a new text document and I'll call it alpha. txt so now I've got a new file created in this repository I'm going to open up the git bash shell and ask about my status git status and it will say to me there's a file named alpha. txt that's untracked and I'll be like well let's track that get add that to the tracking index the staging index so alpha. txt gets added I can now ask for the status again and we're told everything's good all we need to do is commit I'm the type of man that does what he's told and I'm not afraid of commitment so I'll say git commit DM I don't know SSH gitlab example will be a a bad get commit message so now we've done the commit now we want to push these files up to the server and as you can see we currently only have the gitlab CI yaml file the readme in the index.html on the server we want to push alpha. txt up there so we just say get push click enter and boom It Gets Sent up to the server using SSH come over here do a quick refresh and you can see boom all of a sudden we now have alpha. txt on the server so now we're doing gitl SSH pushes using these uh gitlab SSH keys that we generated um and so that's the push so we saw the Clone we saw the push um now of course if somebody else adds something to the server would we want to do a poll so we can actually simulate that here I can actually create a new file up on gitlab using the web interface for gitlab so I'll go in there say create a new file let's see what will we name it well we'll call it bravo. txt hello SSH gitlab example World there we go commit the changes and so now we've got the opposite situation right our server is out of sync with our local F system our local F system is one commit behind it doesn't have Bravo so again how do we solve this well it's easily solve we just say get pull and the pull will cause us the cause git to locally pull the changes from the server doing that gitlab SSH key handshake behind the scenes so we say get pull and boom all of a sudden you now see bravo. txt at the file some things are are in sync once again so there you go that's how easy it is to set up SSH keys in gitlab you just generate the keys find them in the SSH folder copy the public key set up the SSH public key in git lab get the SSH URL then clone using that SSH URL and then everything should go swimmingly from there on in by the way if you do get an SSH public key permission denied error one of the things I suggest is going into gitlab deleting the existing Keys up in gitlab and then deleting the keys in the SSH folder locally and recreating them now you might want to back those keys up before you do it or you might want to get permission make sure no one else is using the keys that you're deleting up on gitlab right if you're working in a team maybe just deleting everything off the face of the Earth isn't the greatest strategy but if this is something you're doing locally just trying to get things set up initially that is a good strategy right eliminate as many variables as possible so there you go uh that's how easy it is to just get up get set up with SSH and gitlab now I did ask you two things I said if you got this working do me two favors speak nicely of me and check out my git and gitlab tutorial that's 2 hours very complete and I think you'll really enjoy it it needs some views so give it a like up and share it with your friends if you're interested in any of the stuff that I'm doing uh my name is Cameron McKenzie I'm the editor and chief at the servers side.com we've got lots of great tutorials on git and gitlab and devops tools Java python scrum agile you name it um I'm also doing a lot of work in the AI and machine learning space right now and there's a new programming language poised to replace python called Mojo uh if you're in the software development state it it space it behooves you to really learn about this new programming language and I talk about a lot of that in my newsletter so there's a link to my newsletter in the description if you want to keep up to the date on the very latest trends that are going on in the software development industry you really need to to sign up for that newsletter um I do have a couple of books so I wrote a book called Pickering is Springfield and hibernate me easy those are in the back and I'm also working with a young freelancer named Darcy declute who just published the scrum Master certification guide so if you're agile you know anybody interested in getting scrum Master Certified that is the only book you need and there you go that's about it um I don't know what else to say other than the fact that if you're watching this on YouTube give this a thumbs up put a comment in the comment section and subscribe on YouTube s
Info
Channel: Cameron McKenzie
Views: 9,605
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: 4f1MJuGfjx4
Channel Id: undefined
Length: 14min 32sec (872 seconds)
Published: Tue Jan 30 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.