Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Use an SSH Key with Visual Studio Code

Create an SSH key, add it to GitHub or GitLab, and clone a repository in VS Code without typing a password.

How-To Guides2 min read4 steps9 screenshots

How SSH keys work

An SSH key is a pair of two files.

  • The public key goes to the service, such as GitHub or GitLab.
  • The private key stays on your computer. Never share it.

Before you start, install Git and Visual Studio Code on your computer.

Step 1: Create the key

Windows: open Git Bash from the Start menu. Linux and macOS: open Terminal. Run:

ssh-keygen -t rsa -b 4096 -C "you@example.com"

Replace the email with your own. Press Enter to accept the default file location. On Windows this is C:\Users\your_user_name\.ssh\id_rsa. You may add a passphrase for extra safety, or press Enter to skip it.

Creating the key in Git Bash
Creating the key in Terminal

Step 2: Add the key to the SSH agent

The agent remembers your key for the session.

Windows (Git Bash):

eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
Starting the SSH agent
Adding the private key

Linux and macOS:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
The SSH agent on Linux

Step 3: Add the public key to your Git service

Show the public key and copy the whole output:

cat ~/.ssh/id_rsa.pub
The public key in the terminal

GitHub: click your picture, then Settings, then SSH and GPG keys. Click New SSH key, type a title, paste the key and click Add SSH key.

Adding the key on GitHub

GitLab: click your picture, then Settings, then SSH Keys. Paste the key and click Add key.

Step 4: Clone a repository in VS Code

  1. Press Ctrl + Shift + P (Cmd + Shift + P on macOS) to open the Command Palette.
  2. Type Git: Clone and choose it.
    Git: Clone in the Command Palette
  3. Enter the SSH address of your repository, for example git@github.com:username/repository.git, and press Enter.
  4. Pick a local folder for the project.

Step 5: Test the connection

ssh -T git@github.com

You should see a short welcome message with your user name.

A successful SSH test

If it does not work

  • Fix the key permissions: chmod 600 ~/.ssh/id_rsa
  • Start the agent again and re-add the key with the two commands from step 2.
  • Check that the repository address is the SSH one, not the HTTPS one.

Quick recap

  • Create a key pair, add the private key to the agent, and the public key to GitHub or GitLab.
  • Use Git: Clone with the SSH address.
  • Test with ssh -T git@github.com.