Lectures‎ > ‎

Week03

ssh keys setup

The basic idea is to generate a private/public key pair (these are just two files that will live your ~/.ssh directory. You will create a key pair on your laptop, then add the public key to your Raspberry Pi so that you will be allowed to ssh into your Raspberry Pi without a password. You will have to type your passphrase once each time you boot your laptop, but generally you will not have to type a password.

On local computer (your laptop) works on Mac, Linux, cygwin on Windows. 

<hostname> below is your hostname for your Raspberry Pi. Replace all the characters including "<" and ">" with your hostname.

For example, if you hostname is mypi, then

Host <hostname>.local

becomes

Host mypi.local

Also, when you see something like:

$ cat > foo
hello
world
^D

You should type "cat > foo", then copy the following lines up to, but not including ^D and paste them into your terminal. Press the RETURN/ENTER key, then type ^D.


$ cd # go into home directory
$ mkdir .ssh
$ cd .ssh
$ ssh-keygen -t rsa -f rpi_rsa
$ cat > config
IgnoreUnknown UseKeychain
UseKeychain yes

Host <hostname>.local 
  AddKeysToAgent yes 
  ForwardAgent yes
  IdentityFile ~/.ssh/rpi_rsa 
  User pi
^D
$ chmod 600 *
$ chmod 700 ../.ssh
$ cat rpi_rsa.pub

Copy contents of rpi_rsa.pub and put on RPi:

On RPi

$ cd
$ mkdir .ssh
$ cd .ssh
$ cat > rpi_rsa.pub
<PASTE contents of rpi_rsa.pub, output of cat rpi_rsa.pub above>
^D
$ cp rpi_rsa.pub authorized_keys
$ chmod 600 *
$ chmod 700 ../.ssh

Now on your localhost/laptop type:

$ ssh <hostname>.local

Using git and GitHub for Projects

I will post the GitHub classroom links to create repositories to Piazza.

You will need to install git on your RPi (your RPi must be connected to the Internet):

$ sudo apt-get install git

You may have to update apt on your RPi:

$ sudo apt-get update

I usually create a top-level directory on my Pi for cs315:

$ cd
$ mkdir cs315

Then I create a git subdirectory in cs315 where I put all of my cs315 related github repos:

$ cd cs315
$ mkdir git

First, you should clone the in class example repository:

$ cd git
$ git clone https://github.com/usf-cs315-f19/inclass.git

You can then "cd" into inclass and see all the examples by week number.

You can now clone your Project02 repo.

$ cd ~/cs315/git

(now you are in /home/pi/cs315/git)

$ git clone https://github.com/usf-cs315-f19/project02-<username>.git

(you will use your URL, not this one)

Once cloned, you can cd into the repo:

$ cd project01-<username>

Create a README:

$ echo "# project02-gdbenson" >> README.md

Then add it to the repo:

$ git add README.md

Then commit:

$ git commit -a -m "Added a README"

You will get an error the first time. It will ask you to config git with your email and username. Follow the given directions.

Once you have done this, commit again:

$ git commit -a -m "Added a README"

Then push your changes to GitHub:

$ git push

Now you can added new files or make changes. You always need to explicitly add files with git add. Then you need to commit, then push.

We will go over how to use git from the command line on your RPi to clone your repo and to commit and push your changes.

I will demo this in class in case you have more questions.

Adding your ssh public key to Github

You can also simplify how you work with Github on the command line by adding your public key to Github. In this way, you won't have to type your Github password every time you clone a repo or push commits.

Once logged into Github go to "Settings" from the upper right dropdown menu.

Select "SSH and GPG keys"

Select "New SSH key"

Then copy your public key that you create above into the input box. Remember your public key is the one that end in the .pub extension, e.g., rpi_rsa.pub.



Comments