Week 31 Homework đ» đą
New stuff we learned this week: đ€
SSH Keys, etc. đ
ssh
can be made secure with passwords â but these are very easy to crack, so it is far more common to do SSH securely with cryptographic keys.- ssh keys come in pairs â a private key and a public key. The public key can only be used to ENCRYPT something, so itâs safe to share. The private key can decrypt so it must be kept secret! Hereâs what my main public key looks like:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAABCAQDJ5HZK17ev5FuytPlwxEHvSCMVPnV6cMzAEqhdaZ6JzMRcONy99naxXIDHhPPIhF6CfrgUCFa5lICFbVxpTg5JPBHsCprqUB/WZzd3aOXAhiUu6YJ9fCFciLtkVpmGpFDyjSIm42klUIQ/zSTSUaOqzbZI8ABeQ4YX5Drfh2xVjU3e5CGPiRJBiRQ40t7ocsSt6MYmezB5lTXw8CGCxGnZpZskD05vwV6Q4ZcHVD0iHOH8XqA8PPVQo/dqov/Wt1DlNVEiJjgbRrGrZqz44rFP0CYTBzxwg2u/9q7tLcGxrtxEo8yDTzCCO9Wxa2bPpxARQcEhBugfFp45tDHUiI7gsIoHy8DZDfzbvCd9rsoLfGmuyau2CgnY/vWJe6F+qWI3jzM5t5aOtCe7punWeTe95C0hl9Ja3mGd9MilW+WB5lPQcl+r0scpOg3iS4zVO9j+Z76NHa0DFf1ujr0VsPGzpz5oiTU/bmRaSfrMO0jSmA3DqrvpjaQ5vrCFfcAuh+Wd72oHCjkew3wfyUj32YzlcNcG/8UVLF6n7yLC/h3EHCTVgZff2iNWRzWf1lFRhjD3B+Nx7wPM/FvZe4bC9j1qDJspXM73GHlfk9lVowXc5h0iqa6xfcPfqi+FCsnWo8+HGTEc9wpenT3RdmzR4a2ts1Ld4YL+vLu/aczHP8zUqQ== jared@netrivet.com
- On unix-y computers (linux, mac), the standard place where ssh keys and other
ssh goodies go is in a hidden folder at the path:
~/.ssh
. If you donât have this folder, you can make it:mkdir ~/.ssh
- The most common name and location for a default ssh key is
id_rsa
in your~/.ssh/
directory. It has two parts:~/.ssh/id_rsa.pub
(which is the public key), and~/.ssh/id_rsa
which is the private key. - generating an SSH key is done rarely enough that itâs not really useful to memorize the commands (I always google it).
- the
~/.ssh/authorized_keys
file is a simple, plain-text file with one public key per line. This is where a unix-y computer keeps a list of keys for trusted computers that are allowed tossh
in. - This means, that to get key-based ssh access to a computer somewhere,
you need to put your public key into that computerâs
~/.ssh/authorized_keys
file. - The first time you connect to a remote computer with
ssh
(using password, or key), your computer will always put up a scary warning saying Hey! We donât know for sure what this other computer is youâre connecting to, are you sure you trust it?. The warning looks like this:
The authenticity of host 'radwebsite.com (35.231.145.151)' can't be established.
ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw.
Are you sure you want to continue connecting (yes/no)?
- theoretically, youâre supposed to verify the
fingerprint
to make sure some hacker isnât intercepting your request, but in reality almost noone every does this. If you typeyes
, youâll see this message:
Warning: Permanently added 'radwebsite.com' (ECDSA) to the list of known hosts.
- that message means that now your computer has a record of the digital
fingerprint and IP address for the url
radwebsite.com
. It keeps this record in a special file at the path~/.ssh/known_hosts
. - from that point on, every time you connect to
radwebsite.com
your computer will check that the IP address matches. If it doesnât, you get this scary message:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
51:82:00:1c:7e:6f:ac:ac:de:f1:53:08:1c:7d:55:68.
Please contact your system administrator.
Add correct host key in ~/.ssh/known_hosts to get rid of this message.
Offending RSA key in ~/.ssh/known_hosts:12
Host key verification failed.
- if youâre certain youâre not being hacked, (like maybe you own the server and
you changed itâs IP address), then you just delete the line of
known_hosts
that the warning points you to. (see the second to last line of the example above). - one more interesting file that you can make in your
~/.ssh
dir is a plain text file calledconfig
. This is like a place to storessh
configuration settings for different hosts. For example, if you always typessh tabitha@howtocomputer.link
, you could tell yourconfig
file that you always want to use the usertabitha
when connecting tohowtocomputer.link
. You do that like this (in~/.ssh/config
):
Host howtocomputer.link
User tabitha
IdentityFile ~/.ssh/id_rsa
- if you have this in your
~/.ssh/config
file, then you can just typessh howtocomputer.link
and youâre golden! (I think it also unlocks tab-completion for the host as well đ). - if you get confused on any of this, simply refer to this diagram:
Github / Gitlab
- GitHub is a website/company that facilitates easier collaboration on
software projects using
git
. - GitLab is the same thing, a competitor/alternative to GitHub.
- inside of GitLab, you can clone a repository owned by someone else by pressing the fork button at the top of the repository. The purpose of a fork is usually to be able to push branches to your own copy of a repo, and then possibly open a Pull/Merge request to the original repo.
- a Merge Request (or Pull Request) is a request to have a branch
merged into another repo. Github/Gitlab create a nice web page for PRs that
allows you to see a web-based
git diff
and to make comments and have a discussion about the proposed changes. The web page has a button (for the repo owner) that allows them to merge the changes with a click. - Github/Gitlab gives you ssh clone URLs so that you can clone repos down to your own computers and work on them there, and then push/pull changes via ssh.
- in order to do git clone/pull/push/fetch using
ssh
you have to paste your computers public key into the web interface. Behind the scenes, GitLab puts your public key into itâsknown_hosts
file.
Useful Links:
Flashcard Assignment
- add 4 new
unix
flashcards:~/.ssh
directoryknown_hosts
fileauthorized_keys
file~/.ssh/config
file
Homework Plan:
- 1 day adding to and reviewing flashcards
- 2 days SSH Homework
- 1 day GitLab Homework
- 1 day Web Homework
- 2 days touch typing practice
- 2 days watch CCCS #28
Homework day 1
Homework day 2
Homework day 3
Homework day 4
SSH Homework #1
- carefully review the âNew stuffâ above
- do your flashcard assignment first
ssh
into your home dir- check if you have a
.ssh
folder (youâll have to use a flag to see hidden folders, because the folder begins with a.
) - create the
~/.ssh
folder if it doesnât exist, then move down into it - ok, next weâre going to create a brand new SSH key pair, NOTE: change the email address in the command below
- type this command, substituting your own email address:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- accept the default filename of
~/.ssh/id_rsa
- lease passphrase empty by just hitting enter twice
- now do a
ls
and you should seeid_rsa
andid_rsa.pub
- cat out both of your key files so you can see the contents
- type a command that will allow you to see the permissions of both of your new ssh key files
- if they are not already correct, change them to:
id_rsa.pub
should be set to-rw-r--r--
id_rsa
should be set to-rw-------
- congrats, youâve made an ssh key, now we just need to get the public key onto another server so we can use it.
- cat out the public key and copy it
- next, one time weâre going to
ssh
into the practice machine I made using a password. To do that, typessh <your-name>@ssh-practice.howtocomputer.link
. The password is the one I showed you in class yesterday. - once youâre connected to the practice computer, make a
~/.ssh
folder and inside it, create anauthorized_keys
file that contains one line â the ssh public key you copied in step 15. - exit out of the practice computer, which will bring you back to the HTC computer.
- now, you should be able to connect to the practice computer without being
prompted for a password. Try it by typing
ssh <yourname>@ssh-practice.howtocomputer.link
. If you get in without typing the password, it worked! If not, try to review the previous steps carefully checking if you did each on correct. - log out of the practice computer, back to the HTC computer.
- next, create a file with something in it that will make it so that you donât
have to supply the
<yourname>@
part of the ssh command. Review the ânew stuffâ if youâre not sure what to do. Youâll know you did it correctly if you can ssh directly to the practice computer by typing onlyssh ssh-practice.howtocomputer.link
.
SSH Homework #2
- complete SSH homework #1 first
- on your own computer, cd into your home dir, and create an
.ssh
dir if it doesnât exist. cd
into the~/.ssh
dir, and do als
to make sure thereâs not already aid_rsa
key pair. If there is (which I doubt), Slack me and Iâll tell you what to do.- use the same command from part 1 of the ssh homework to generate a ssh key pair, and then make sure that the permissions are correct.
ls
andcat
to see that you have made a new pair, and look inside both of them for fun.- BEFORE you try to use the key, weâre going to do 2 or 3 extra steps to make sure this works.
- first, in your shell, type this command exactly (you donât need to understand
what it does):
eval "$(ssh-agent -s)"
- the second step is only for Mac computers, skip if youâre not on a Mac. If
you are on a Mac, create a
~/.ssh/config
file and put these lines in it:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
â third, if youâre on a Mac computer, type ssh-add -K ~/.ssh/id_rsa
. If
youâre on Linux type: ssh-add ~/.ssh/id_rsa
- after all that, copy your new public key to a
~/.ssh/authorized_keys
file on the HTC computer. - log out of the HTC computer and test if you can make a connection without entering your password.
- assuming you got that working, modify the ssh config file on your own computer so that you also donât need to type your name.
- if you did all the steps right (and my instructions are good đ€) then you
should now be able to ssh into the HTC computer by only typing
ssh howtocomputer.link
.
GitLab Homework
- do the SSH homework (both parts) first
- visit gitlab.howtocomputer.link and click the âRegisterâ tab. Fill out the form to create a new account, making sure to remember your password.
- once youâre logged in, send me a Slack so I can add you to the How to Computer group.
- spend a few minutes (but not too long, OK?) clicking around and exploring all the places you can go. See how many of them you can understand.
- find the place where you can set your profile picture, and upload a picture
- try to find the group I made called
How to Computer
. Once you find it, click into one or two of the repositories. Try to get a little familiar with how GitLab gives you a webpage view of a git repository. - find the place in GitLab where you can paste a ssh public key. Once you find
it, log into the HTC computer, then cat out and copy the public key you made
in SSH Homework #1. Paste it into the GitLab web UI and give it the name
howtocomputer.link machine
so you donât get confused later if you add another key. - try to find the main repository webpage for the homework site repo. Itâs one of the repos in the HTC group. Youâll know youâre on the right page if you see a BLUE clone button in the upper right, but donât click it! If after poking around for a little while, you canât find it, click here to go straight there.
- on that page, look at the URL in the browserâs address bar, youâll see it ends
with
/htc/homework-site
. The pattern is this:/<owner>/<repo>
. So in this case,htc
is the owner (thatâs the group I made) andhomework-site
is the slug of the repo itself. Does that make sense? - next, find the fork button in the upper right of the page and click it. Choose to fork it into your own name (that will be the only option).
- once forking is complete, you should be taken to the webpage for your own copy of the repo. Look at the URL in the browser address bar again. Do you see how it changed? Does it make sense what the two parts of the URL are?
- now, here on your forked copy of the repo, click the blue clone button and
then copy the
ssh
url. - next,
ssh
into your home dir. Youâre now going to clone the homework site right into your home dir. To do that, typegit clone <the-url-you-copied>
. If the clone is successful, that means you got your ssh key set up correctly. Hooray! - now cd into the
homework-site
dir that git created for you when you cloned. - type a command to see if you have any git remotes. Do you understand why you have one, and why it is called what it is?
- type a command to see more information about the git remotes â you should be
able to see that your
origin
remote is coming from gitlab. Cool, huh? - make a new branch name (called whatever you want) and switch to it.
- open the file that contains the page youâre reading right now, it is (from the
repo root dir) in the path
src/markdown-pages/week-31.md
â open it with vim. - donât worry if you donât understand all of what you see (itâs written in a
format called
markdown
which I havenât taught you yet, but itâs similar to how you can type special things in Slack) - Find part of this homework page that you think could be improved or made more clear. If you noticed a mistake, or something like that, use vimâs search feature to find that chunk in the code. Once you found something to change, make the change and commit your work.
- next youâre going to push your branch up to your own fork on GitLab (try
telling that to your mom and see what she says, haha). To do this, youâll use
the
git push
command, in the format:git push <remote> <branch>
. - if you did it right, you should see a URL show up in the terminal output offering you to create a Merge Request. You can either copy that URL, or try holding down command or control and clicking right on it. Most terminals will allow you to click a URL if you hold down command or control. But if clicking doesnât work, just copy the URL and paste it into a new tab of your web browser.
- on the Merge Request screen, edit the title and description to give me a nice explanation of why I should merge your changes, then click to submit the PR.
- slack me with the URL of your Merge request so I can look it over!
Web Homework
- NOTE: make sure you have done the GitLab homework first. Go to the HTC group
on GitLab, and find the repo called
week-31-cars
- make your own fork of the repo
- clone the repo down into a
~/www/week31
dir that you create after ssh-ing in to the HTC computer. - once itâs cloned, cd into the repo, and make and switch to a new branch.
- edit the
app.js
file: - turn the big string I gave you into a nice usable array (hint: the name of the variable should give you clue) â this can be done in one line of javascript
- map over the array you have, creating a
li
dom node for each, containing the name of each car (this is very similar to last weeks homework) - use
Array.forEach
to insert each list item into the Dom, into theul
element I gave you. - commit your work
- You should see a list of a handful of car names
- next, edit your code so that each list item also displays the horsepower, and adds a sad emoji if the car is out of stock
- commit your work.
- change you code now to remove the âout of stockâ emoji. Instead, use
Array.filter
to only show cars that are in stock. - commit your work.
- if you didnât already use them, refactor your code to use an arrow function
for the predicate passed to
Array.filter()
- commit your work.
- submit me a Merge Request, and then slack me the Merge Request URL.
- When I get the MR, Iâm going to review your code and make a few suggestions for improvements. Youâll need to address my feedback, make a new commit, and push back up your branch.
- after you address my feedback, Iâm going to give you each one or two more mini-features that I want you to implement, but Iâll communicate this through the MR. Youâll need to implement the mini-feature/s I request, and then push up another commit.
- Iâll have one more quick step for you to do after that, that Iâll tell you about when you get there.