📝 Exercise 2: Getting Started with GitHub
Instructions: Complete the following activity to set up your GitHub account.
🎯 When you've completed the activity, don't forget to click the 'Mark as done' button at the top left of this page. This helps track your course progress and ensures you receive your course badge without delay.
1. Creating a GitHub Account
You can set up a GitHub account by visiting the official GitHub website at https://github.com/. More details available in the official documentation on GitHub: Signing Up for an Account if needed.
2. Adding an SSH Key to GitHub to Establish a Secure Connection
After setting up your GitHub account, you are ready to connect your local Git repository to GitHub. There are two ways to do this, either through HTTPS or SSH.
SSH (Secure Shell) is the recommended method to use because it provides a secure, password-less connection between your computer and GitHub.
How you do this depends on your computer's operating system as well as the particular terminal or client that you’re using to access the systems. See the instructions on the SciNet or Alliance documentation sites (for Linux/Mac, for Windows).
What is an SSH key?
An SSH key is like a digital ID card that proves to GitHub that it's really you when you're pushing code from your computer.
An SSH key comes in pairs:
- Private key - stays on your computer (never share this key with anyone).
- Public key - gets copied to your GitHub account (this key is present on your local machine as well as GitHub).
Once set up, GitHub can verify that it's you, and you won't need to enter your username and password every time you upload or download code. If you choose to set a passphrase, you will then use that passphrase to access your remote repository (which you can setup in Step 3 below).
How to Generate an SSH key (Mac, Linux, or Git Bash on Windows)
- Open your terminal
- Generate the key pair by copying and pasting the following command and press Enter:
-
$ ssh-keygen -t ed25519
-
- Follow the prompts, it will ask you two pieces of information:
- Where to save the key
- To set a passphrase for using the key
- Copy the SSH key to add to your GitHub account
- Run one of following command lines in your terminal to copy:
-
#
General method to display an SSH key:
$ cat ~/.ssh/id_ed25519.pub
-
#
For macOS users: running the following command line will directly copy your public SSH key to your clipboard
$ pbcopy < ~/.ssh/id_ed25519.pub
- Then go to your GitHub account:
- Settings > SSH and GPG keys > New SSH key
- Paste the key and give it a name (e.g. "My Laptop")
- Test the connection:
-
$ ssh -T git@github.com
- If everything is setup correctly, GitHub will greet you by your username.
-
- Load your private key to the ssh-agent
-
In order to have access to this SSH key for connecting to GitHub from a public system such as Trillium, you will need to use an SSH key agent. To set up the SSH key agent, use the following commands in the terminal on your local machine:
-
$ ssh-add ~/.ssh/id_ed25519
Enter passphrase for ~/.ssh/id_ed25519
Identity added: ~/.ssh/id_ed25519 (~/.ssh/id_ed25519) - For more details on loading your private key to the ssh agent for accessing public systems, please refer to the section titled 'Copying a file on another cluster to Niagara' from the SciNet Documentation Wiki page.
-
How to Add New SSH Key on GitHub
The following video demonstrates how to navigate to the 'Add new SSH Key' page on the GitHub interface after you sign into your account.
Note: If you connect to SciNet supercomputers (e.g. Trillium) as part of your workflow, it is important to understand that you should never create SSH keys on Trillium. Even though Trillium is a secure system, it is a public system, and you should never create or store private SSH keys on a public system.
Additional Documentation
- For a more detailed understanding of SSH keys, you can visit the SciNet SSH documentation. For a step-by-step guide and help with other systems, see GitHub's official Guide: Connecting to GitHub with SSH.
If you're feeling stuck completing this exercise, please feel free to pose questions or consult the Discussion Forum.