DEV Community

Cover image for [YuIT Docs📜] Create a new SSH key🔑
YuIT Solutions
YuIT Solutions

Posted on • Edited on

[YuIT Docs📜] Create a new SSH key🔑

Create a new SSH connection between your local machine and GitHub

1️⃣ Open the Terminal of VScode and generate a New SSH Key

ssh-keygen -t ed25519 -C "my-key"
- Enter file in which to save the key (C:\Users\someuser\.ssh\id_ed25519): 
- C:\Users\someuser\.ssh\id_ed25519 already exists.
- Overwrite (y/n)? y
- Enter passphrase for "C:\Users\someuser\.ssh\id_ed25519" (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in C:\Users\someuser\.ssh\id_ed25519
Enter fullscreen mode Exit fullscreen mode

2️⃣ Go to our directory with private and public keys:

cd ~/.ssh
Enter fullscreen mode Exit fullscreen mode

3️⃣ Copy the SSH Public Key

For windows

cat id_ed25519.pub | clip
Enter fullscreen mode Exit fullscreen mode

For macos

cat id_ed25519.pub | pbcopy
Enter fullscreen mode Exit fullscreen mode

4️⃣ Add the SSH Key to Your GitHub Account

  • Log in to GitHub
  • Go to Settings > SSH and GPG keys
  • Click New SSH key
  • Paste your key into the "Key" field
  • Add a descriptive title
  • Click Add SSH key

Or add the SSH Key to Your GitLab Account

  • Sign in to GitLab
  • On the left sidebar, select your avatar
  • Select Edit profile
  • On the left sidebar, select SSH Keys
  • Select Add new key
  • Select Key, and you should see the 1Password helper appear
  • Select the 1Password icon and unlock 1Password.
  • You can then select Create SSH Key or select an existing SSH key to fill in the public key

5️⃣ Test the SSH Connection

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

or

ssh -T git@gitlab.com
Enter fullscreen mode Exit fullscreen mode

Summary:

- Generate SSH key (ssh-keygen)
- Add key to SSH agent (ssh-add)
- Copy public key (cat ~/.ssh/id_ed25519.pub) and add to GitHub or Gitlab
- Test connection (ssh -T git@github.com or ssh -T git@gitlab.com) 
- Use SSH URL for repositories
Enter fullscreen mode Exit fullscreen mode

Guide to add a file, commit your changes, and prepare for pushing to GitHub:

Step 1. Clone your Repositories

cd C:/MyPath/GitHub/
git clone git@github.com:username/repository.git
Enter fullscreen mode Exit fullscreen mode

Step 2. Add your new or modified files

To stage a specific file:

git add filename
Enter fullscreen mode Exit fullscreen mode

To stage all changed files:

git add .
Enter fullscreen mode Exit fullscreen mode

Step 3. Commit your changes with a descriptive message:

git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode

Step 4. Push your changes to GitHub

git push origin main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)