Locked lesson.
About this lesson
SSH keys allow our project to talk to other services securely behind the scenes. In this lesson, we'll discuss how to create and use an SSH key of your own.
Exercise files
Download this lesson’s related exercise files.
Create SSH Keys.docx57.5 KB Create SSH Keys - Solution.docx
58.3 KB
Quick reference
Create SSH Keys
An SSH Key allows us to connect our terminal to third party services securely for transferring files.
When to use
Create an SSH Key when you plan to transmit your project files to a third party such as github.com or heroku.
Instructions
To create an ssh key, first create a directory:
mkdir ~/.ssh
Next move into that directory:
cd ~/.ssh
Next create the ssh key:
ssh-keygen.exe
Follow the on screen prompts.
Hints & tips
- Create and save your ssh key in the ~/.ssh directory
- to create your key: ssh-keygen.exe
- 00:04 Okay, so we've got our app done.
- 00:06 Now we want to start the process of pushing it up to web hosting.
- 00:09 But before we want to do that we really want to use version control to
- 00:14 save our code to someplace like GitHub.
- 00:17 And after that, we'll push our code up to Heroku for web hosting.
- 00:21 And I'll talk about Heroku later what it is and why we're going to use it.
- 00:25 But for both of those things, we need to create an SSH key, a secure key.
- 00:29 And that's what we're going to do in this video.
- 00:31 So an SSH key just allows us to sort of talk to different
- 00:35 services behind the scenes securely.
- 00:38 So we're going to push our code to GitHub.
- 00:40 We're going to push our code to Heroku.
- 00:41 And to do that securely, we need a secure key.
- 00:44 And that's what we're going to build in this video.
- 00:46 So let's head over to our terminal.
- 00:47 And this is the second terminal that we had set up.
- 00:50 The first terminal is still running our server.
- 00:53 But this is our second one and notice we're in C, mywebsite/djangowebsite
- 00:58 as always, and if we LS just to Remind you, we see this manage.py file.
- 01:03 We always want to see that.
- 01:05 Now, we need to create an SSH key, but we don't want to create it in this directory.
- 01:10 We want to create it in the default directory for our GitHub,
- 01:15 and that is, we can reference it by squiggly line.
- 01:19 So what we want to do is make a new directory to hold our new SSH key.
- 01:23 So first, let's clear the screen.
- 01:24 So what we want to do is make a directory mkdir.
- 01:29 And we want to put this in our default directory which is a squiggly line.
- 01:34 In this squiggly line is located on the top left hand corner of my keyboard and
- 01:38 probably your keyboard too.
- 01:40 So what we want to do is create a directory called .ssh.
- 01:43 And .ssh means that our directory will be hidden, .directories are hidden
- 01:48 directories and that's a security thing that we like, okay.
- 01:52 So let's move into that directory.
- 01:53 So cd, change directory ~/.ssh.
- 02:00 And when we ls, there's nothing in there.
- 02:02 So now we need to create our SSH key.
- 02:05 So to do that, we just type in ssh-keygen.exe.
- 02:12 And this will generate a public and private RSA key pair, which is an ssh key.
- 02:17 And it's asking us, where do we want to save this?
- 02:20 Well, we just want to save it in this directory so we can just hit Enter.
- 02:23 Next, it's asking for a password.
- 02:25 You can type in a password if you want.
- 02:27 I never do.
- 02:28 This is a secure key already.
- 02:29 We don't really need a password for it.
- 02:32 And if you create a password, you going to have to remember it forever.
- 02:34 If you forget it, you're going to have to redo all of this.
- 02:37 So I just don't find any use for it so I don't put a password so
- 02:40 I'm just going to hit enter.
- 02:41 If you do type a password,
- 02:43 you'll notice that it doesn't actually print onto the screen.
- 02:46 The cursor just keeps blinking like it is now.
- 02:49 And that's normal that's a security thing.
- 02:51 Just keep typing and hit Enter.
- 02:53 So like I said, I'm just going to hit Enter.
- 02:55 It's going to ask to retype the password.
- 02:57 I'm going to hit Enter again, and boom, it's been created.
- 03:00 So now if we type in ls, we see these two files, id_rsa, and id_rsa.pub.
- 03:08 And it's the .pub1 that we want.
- 03:10 So we can actually look at this file right now, we can type in cat, and
- 03:15 then id_rsa.pub, and it will print it out to the screen and this is our SSH key.
- 03:21 So very cool.
- 03:22 It looks like a bunch of gobbledygook, but it's the key.
- 03:25 So we can highlight all of this and right click and click Copy.
- 03:29 And later on, we're going to want to copy this thing into our GitHub account.
- 03:33 But for now, we can just sort of ignore this.
- 03:36 What we want to do now is navigate back to this folder.
- 03:40 So let's go cd.
- 03:42 We want to be in, c/mywebsite/djangowebsite.
- 03:49 And when we do, let's clear the screen, we notice we're in our directory.
- 03:54 We have our virtual environment is still turned on.
- 03:56 We can type in ls to make sure yep, there's that managed.py file, and
- 04:00 everything is good.
- 04:01 So that's how you create an SSH key.
- 04:03 And we'll use this going forward a couple of different times, and
- 04:06 that'll be pretty cool.
- 04:07 In the next video, we'll set up version control with Git.
Lesson notes are only available for subscribers.