Setting Up Your Laptop
In the previous lab you set up your course files on a Linux desktop in the computer lab. Today you'll set up your own laptop so it can reach the computer lab and share the same files. By the end of class you'll change a program on one machine, and see the change appear on the other.
You can start before class
Steps 1–3 (file extensions and installers) you can do on your own ahead of time. If you get stuck on anything, that's what class is for; we'll help you get unstuck.
Use the right terminal
- Windows users: always use Git Bash. After you install git, you'll get an app called Git Bash, which gives you the same commands you already learned in the computer lab, so everything matches. Don't use PowerShell or Command Prompt in CS 149.
- macOS users: use the Terminal app. The commands are the same on Linux and Mac.
Step 1: Show file extensions (Windows and macOS)
By default, your laptop may hide the ends of file names, so a file called hello.py shows up as just hello.
That makes it hard to tell your files apart, and today you'll be working with files like config and README.md where the exact name matters.
Turn extensions on first, so you always see the full name:
- Windows: Open File Explorer, click the View menu, and check File name extensions.
- macOS: Open Finder, go to Finder ▸ Settings ▸ Advanced, and check Show all filename extensions.
Step 2: Install Thonny
The Linux desktops in the computer lab already have Thonny, the program you'll use to write and run Python. You need it on your own laptop too. Start this download first, since it can install while you work on the next step:
- Go to https://thonny.org.
- Download the installer for your operating system (Windows or macOS).
- Run the installer and accept the default options.
- Open Thonny once to make sure it launches. You don't need to configure anything yet; we'll finish setting it up together in a later class.
Step 3: Install git
First, check whether you already have git:
If that prints a version number, you already have git, so skip to Part 4. Otherwise, install it:
- Windows: Go to https://git-scm.com/install/, download the Windows installer, and run it. Accept all the default options by just clicking Next. When it finishes, open the Git Bash app and run
git --versionto confirm. - macOS: The easiest way is to install Apple's Command Line Tools, which include git. In the Terminal app, run:
A dialog box will pop up. Click Install and wait for it to finish (it may take several minutes). Then run
git --versionto confirm. It's fine if this isn't the very newest version of git; any recent version works for this course.
Step 4: Tell git who you are
Just like on the Linux desktop, tell git your name and email, but now on your laptop, since it's a different computer. Use your real first and last name and JMU dukes email.
Confirm they took:
You should see your user.name and user.email.
Step 5: Create an SSH key
An SSH key comes in two matching pieces: a private key that stays secret on your laptop, and a public key you can hand out freely. When the server has your public key, it can recognize your laptop's private key, so you can connect without typing a password every time.
Create your key:
It will ask a few questions:
- "Enter file in which to save the key": just press Enter to accept the default location (
~/.ssh/id_ed25519). - "Enter passphrase": press Enter to leave it empty. Press Enter again when it asks to confirm.
When it's done, you have two new files in your ~/.ssh/ folder: id_ed25519 (your private key, never share this) and id_ed25519.pub (your public key, safe to share).
Step 6: Tell your laptop how to reach the student server
You'll create a short config file so you can type ssh stu instead of the full server address every time you want to connect.
Open a file named "config" in the nano text editor:
Type in exactly this, but replace username with your JMU eID (the part of your email before @dukes.jmu.edu):
Don't leave username as-is
If your eID is duke2jm, the last line must read User duke2jm.
A wrong or unedited User line is the most common reason the connection fails.
Save and exit nano: press Ctrl-O then Enter to save, then Ctrl-X to exit.
Step 7: Record the server's identity
The first time you connect to a server, SSH asks whether you trust it. To be sure you're connecting to the real student server and not an impostor, you'll give your laptop the server's known identity ahead of time.
Add the server's public identity to your known_hosts file with this command.
Copy it exactly:
echo 'stu.cs.jmu.edu,134.126.141.221 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILXS19kf1swKRC9GTTiUDyOzra0sYT+kt6Vxd4Q0H9uw' >> ~/.ssh/known_hosts
This appends (>>) one line to ~/.ssh/known_hosts, creating the file if it doesn't exist yet.
Now your laptop already knows the real server, so it won't have to ask in the next step.
Step 8: Give the server your public key
Right now the server doesn't know your key yet, so this first connection will ask for your password (your regular JMU account password). Connect by running:
Type your password when prompted (you won't see anything as you type; that's normal). You should land at a prompt on the stu server.
Now append your public key to the server's list of authorized keys. But first you need your public key. Open a second terminal window on your laptop and run:
Select and copy the entire line it prints (it starts with ssh-ed25519 and ends with something like you@your-laptop).
Back in the terminal that's connected to stu, make sure the .ssh folder exists with the right permissions, then open authorized_keys in nano:
Paste your public key as a new line, then save and exit (Ctrl-O, Enter, Ctrl-X). Fix the file's permissions so SSH will trust it:
Now disconnect from the server:
Test it. Connect again:
This time it should log you in without asking for your password, because your key is doing the work.
If it still asks for a password, ask for help; something in Parts 5–8 needs a second look.
Once you've confirmed it works, exit back to your laptop.
Step 9: Clone your course files to your laptop
Now copy your course files down to your laptop.
Thanks to your ssh stu setup, the address in the following command is short:
This connects to the server, copies your shared repository, and creates a working copy at ~/CS149 on your laptop, the same folder name you used in the computer lab.
Windows users: keep CS149 out of OneDrive
In Git Bash, ~ is your real user folder (C:\Users\your-name), which is exactly where you want CS149 to live.
Do not put it under Documents or OneDrive; syncing your course files through OneDrive causes slow, confusing problems later in the course.
Cloning to ~/CS149 from Git Bash avoids this.
Move into it and look around:
You should see the starter files (README.md, .gitignore, ruff.toml), plus the hello.py you wrote in the previous lab, and the .git folder.
Your laptop and the computer lab now share the same files, with manual sync that you control.
Step 10: Try the full sync
Let's prove it works end to end. You'll change a program on this machine (your laptop), send it up to the shared repo, and then pull the change down on the other machine (a Linux desktop in the computer lab), or the reverse. Your instructor will tell you which machine to start on.
On the first machine, open hello.py (the program you wrote in the previous lab) in Thonny and add a third line, like in this example:
computer = input("Which computer are you on? ")
print("Hello from", computer)
print("Syncing with git works!")
Save it, then run it in Thonny to make sure the program works.
Back in the terminal, from inside the ~/CS149 folder:
You'll see hello.py listed as modified.
Save and send up your change:
On the second machine, open a terminal in ~/CS149 and pull:
Open hello.py in Thonny; your new line is there.
You just changed code on one computer and picked up the change on another, with git carrying it between them.
Summary
Your laptop can now reach the computer lab and share your course files. From here on, the rhythm is the same on both machines:
- Sit down to work:
git pull - Finish up:
git add -A, thengit commit -m "...", thengit push
Pull before you start, push when you stop, and your work will follow you between your laptop and the computer lab all semester.
Bonus: You can run git log to see a history of your commits.