So, you’re working with GitHub or Bitbucket, and someone on your team tells you, “Hey, add an SSH key to your account.” If that sounds a bit intimidating, don’t worry! I’ll walk you through the entire process in plain, simple steps. By the end, you’ll know exactly how to create an SSH key, add it to GitHub or Bitbucket, and keep your setup secure. Let’s get started!
🔑 What’s an SSH Key, and Why Do You Need One?
SSH keys are a way of securely connecting your local computer to a remote Git server like GitHub or Bitbucket. They allow you to authenticate without entering a password each time, which is not only convenient but also more secure. It’s like having a digital pass that only you can use.
Let’s dive into generating and adding an SSH key!
đź’» Step 1: Open the Terminal
On a Mac, you’ll need to use the Terminal to create an SSH key. To open Terminal, press Command + Space, type “Terminal,” and press Enter.
🔨 Step 2: Generate the SSH Key
In Terminal, type the following command:
ssh-keygen -t ed25519 -b 256
Breaking it down:
-
ssh-keygen
is the command to generate an SSH key. -
-t ed25519
specifies the type of algorithm to use. ED25519 is more secure than the older RSA algorithm, so we use it here. -
-b 256
sets the bit size to 256, which is a solid standard.
Press Enter. You’ll be asked where to save the key. By default, it will go in your ~/.ssh
directory. Press Enter to keep it there.
đź”’ Step 3: Set a Passphrase (Recommended)
Next, you’ll be prompted to enter a passphrase. This passphrase adds an extra layer of security in case someone gains access to your computer. Type a passphrase, and remember, it won’t show anything as you type (for security). Press Enter, then re-enter the passphrase when prompted.
đź“‹ Step 4: Find and Copy the Public Key
Now, you’ll need to copy the public key. The command below will print it in Terminal so you can copy it easily:
cat ~/.ssh/id_ed25519.pub
Highlight the entire output (which looks like a long string of letters, numbers, and symbols), and copy it.
⚙️ Step 5: Add the Key to Bitbucket
If you’re using Bitbucket, here’s what to do:
- Go to your Bitbucket account and click on your profile picture.
- Navigate to Personal Settings.
- Under Security, find SSH Keys.
- Click Add Key.
- Paste the public key you copied, and give it a label (e.g., “MacBook Pro”).
- Click Add Key.
Done! 🎉
đź”— Step 6: Add the Key to GitHub
For GitHub, the steps are similar:
- Go to GitHub and click on your profile picture in the top-right corner.
- Click Settings.
- Go to SSH and GPG keys in the left sidebar.
- Click New SSH Key.
- Name your key (e.g., “MacBook Pro”) and paste the key.
- Click Add SSH Key.
That’s it! Your SSH key is now linked to GitHub. 🎉
đź“‚ Step 7: Load the SSH Key into Memory
Each time you restart your computer, you may need to load your SSH key into memory. To do this, run the following command in Terminal:
ssh-add
When prompted, enter your passphrase to load the key into memory.
âś… Step 8: Test by Cloning a Repository
To ensure everything’s working, try cloning a repository from GitHub or Bitbucket:
git clone git@github.com:yourusername/yourrepository.git
The first time, it might ask if you trust the host (GitHub or Bitbucket). Type “yes” and hit Enter. If it clones successfully, you’re all set! 👍
đź’ˇ Bonus Tip: Create a Separate SSH Key for Each Device
If you’re working on multiple computers, I recommend creating separate SSH keys for each. This way, if one computer is lost or compromised, you can revoke that specific key without disrupting access on your other devices.
🎉 That’s It!
Congratulations! You’ve set up SSH keys for GitHub and Bitbucket. Now you can push, pull, and clone repositories without constantly entering passwords.
If you found this helpful, consider giving a thumbs-up or leaving a comment. Happy coding! 🚀
Top comments (0)