tutorials
SSH keys for Git
Overview
This tutorial introduces SSH keys for Git-based coursework.
An SSH key lets your computer prove that it belongs to you without asking you to type your account password every time you clone or push a repository. In courses that use Class Maestro and Forgejo, you register your public SSH key in Class Maestro, and Class Maestro associates that key with your course Forgejo account.
Outcomes
After completing this tutorial, you should be comfortable…
- checking whether you already have an SSH key
- generating a new SSH key
- adding your SSH key to the SSH agent
- copying your public key
- registering your public key in Class Maestro
- using SSH clone URLs with Git
Prerequisites
This tutorial assumes that …
- You are comfortable with the basics of the Linux command line
- You have installed and configured
git - You have access to the course Class Maestro site
Background
Public and private keys
An SSH key comes in a pair:
- The private key stays on your computer.
- The public key can be uploaded to services such as Class Maestro, Forgejo, or GitHub.
The public key is safe to share with the service you want to access. The private key is not.
Why use SSH for Git?
Git can connect to a remote repository over HTTPS or SSH. HTTPS often requires a password or token. SSH uses your registered key instead.
For course repositories, SSH is useful because one key can identify your development machine to your course Forgejo account after you register the key in Class Maestro.
Checking for an Existing Key
Open a terminal and list your existing SSH keys:
ls ~/.ssh
Look for files with names like:
id_ed25519
id_ed25519.pub
id_rsa
id_rsa.pub
Files ending in .pub are public keys. Matching files without .pub are private keys.
If you already have an id_ed25519.pub file, you can probably use it for this course. If you do not have one, generate a new key.
Generating a New Key
Use ssh-keygen to create a new Ed25519 key:
ssh-keygen -t ed25519 -C "your-netid@arizona.edu"
Replace your-netid@arizona.edu with the email address you use for the course.
When prompted for the file location, press ENTER to accept the default:
Enter file in which to save the key (/home/you/.ssh/id_ed25519):
When prompted for a passphrase, choose one of these options:
- Press
ENTERfor no passphrase if your instructor recommends the simplest setup for a course VM. - Enter a passphrase if you want extra protection for the key on your computer.
If you set a passphrase, you may need to enter it when using the key unless your SSH agent remembers it.
Adding the Key to the SSH Agent
The SSH agent remembers unlocked keys during your login session.
Start the agent:
eval "$(ssh-agent -s)"
Add your key:
ssh-add ~/.ssh/id_ed25519
If you used a passphrase, enter it when prompted.
Copying Your Public Key
Print your public key:
cat ~/.ssh/id_ed25519.pub
Copy the entire output. It should start with ssh-ed25519 and end with your email address or key comment.
It will look roughly like this:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyData your-netid@arizona.edu
Do not copy the private key from ~/.ssh/id_ed25519.
Registering Your Key in Class Maestro
Open Class Maestro and sign in with the email address connected to your course account.
Find the SSH key settings for your account. Paste your public key into the SSH key field and save it.
After you save the key in Class Maestro, it is associated with your course Forgejo account. This is what allows Forgejo to recognize SSH operations from your computer.
Using an SSH Clone URL
After your key is registered, open your repository from Class Maestro or Forgejo and copy the SSH clone URL.
It may look something like this:
ssh://git@git.hlt.parsertongue.org/course/assignment-repo.git
Clone the repository:
git clone <ssh-repository-url>
Move into the repository and check the remote:
cd <repository-name>
git remote -v
You should see an SSH URL for origin.
Troubleshooting
Permission denied
If git clone or git push says Permission denied (publickey), check these items:
- You copied the SSH clone URL, not the HTTPS clone URL.
- You registered the public key in Class Maestro.
- You copied the key ending in
.pub. - You added the matching private key to your SSH agent with
ssh-add. - You are using the same computer where the private key exists.
I copied the wrong key
If you accidentally copied a private key into a form, issue, message, or email, tell course staff immediately and generate a new key pair.
I use more than one computer
Each computer needs its own key pair, or you need to securely move the private key between computers. For most students, it is cleaner to generate a separate key on each computer and register each public key in Class Maestro.