Creating SSH Keys and Cloning a Github Repository
Step 1: Open the Terminal
- Mac: Press
Command+Space, type “Terminal” and pressEnter. - Windows: Press
Windowskey +R, typecmdand pressEnter.
Step 2: Check for Existing SSH Keys
-
In the terminal, type the following command and press
Enterls -al ~/.ssh -
f you see files like
id_ed25519andid_ed25519.pub, you already have SSH keys. If not, continue to the next step.
Step 3: Generate a New SSH Key
-
In the terminal, type the following command and press
Enter:ssh-keygen -t ed25519 -C "your_email@example.com"Replace
your_email@example.comwith your email address. -
When prompted to “Enter a file in which to save the key,” press
Enter. This accepts the default file location. -
Next, you will be asked to enter a passphrase. You can press
Enterto skip this step, but it is recommended to enter a passphrase for added security. If you enter a passphrase, you will need to enter it each time you use the SSH key.
Step 4: Add Your SSH Key to the SSH-Agent
-
Start the SSH agent by typing the following command and pressing
Enter:eval "$(ssh-agent -s)" -
Add your SSH key to the agent by typing the following command and pressing
Enter:ssh-add --apple-use-keychain ~/.ssh/id_ed25519This command will add your key and save the passphrase to the macOS keychain. For Windows, use the command:
ssh-add ~/.ssh/id_ed25519
Step 5: Add the SSH Key to Your GitHub Account
-
Copy the SSH key to your clipboard by typing the following command and pressing
Enter:cat ~/.ssh/id_ed25519.pubThis will display your public SSH key in the terminal.
-
Select and copy the entire key.
-
Open your web browser and go to GitHub (or your Git repository provider).
-
Log in to your account and go to the SSH keys section:
- GitHub: Click on your profile picture, go to “Settings,” then “SSH and GPG keys,” and click “New SSH key.”
- GitLab: Click on your profile picture, go to “Settings,” then “SSH Keys,” and click “Add SSH Key.”
-
In the “Title” field, enter a descriptive name for the SSH key (e.g., “My Computer”).
-
Paste your SSH key into the “Key” field.
-
Click “Add SSH key” or “Add key” to save it.
Step 6: Clone the Repository
-
Go to the repository you want to clone on GitHub (or your Git repository provider).
-
Click the “Code” button and make sure “SSH” is selected.
-
Copy the repository SSH URL.
-
In the terminal, navigate to the directory where you want to clone the repository by typing
cdfollowed by the directory path and pressingEnter. For example:cd /path/to/your/directory -
Clone the repository by typing the following command and pressing
Enter:git clone git@github.com:username/repository.gitReplace
usernameandrepositorywith the appropriate names.
Done!
You have successfully created an ed25519 SSH key, added it to your GitHub account, and cloned a repository to your local machine.