github

ssh-key

To change the authentication mechanism to SSH keys in Visual Studio Code and GitHub, you need to follow these steps:

  • Open the command line and change in your homedirectory if not already done cd %USERPROFILE%
  • Generate an SSH key pair on your local machine using the command ssh-keygen -a3 -t ed25519 -C "your_email@example.com" -f .ssh/id_github.
    • In case you omit the -f option nameing the file where the key should be stored, you will be asked th enter the name of the file where the key should be stored e.g. id_github. Make shure not to overwrite existing keys.
  • Next enter a passphrase (twice)
    • When you generate an SSH key pair, you have the option to add a passphrase to the private key. A passphrase is an extra layer of security that helps protect your private key from unauthorized access. If someone gains access to your private key, they can use it to authenticate as you and perform actions on your behalf. By adding a passphrase, you make it more difficult for someone to use your private key without your permission.
    • When you use an SSH key with a passphrase, you will be prompted to enter the passphrase every time you use the key. This can be inconvenient, but it ensures that only you can use the key to authenticate with remote servers. You can also use an SSH agent to store your passphrase so that you don’t have to enter it every time you use your key .
    • The location of your keys will be shown (e.g. id_github for the private key and id_github.pub for the public key) next to a fingerprint and a randomart image like
+--[ED25519 256]--+
|     ..   .+=.o  |
|      .+ . o+*   |
|    . +.. ooo.o  |
|     +.B.+= =.o  |
|      =+S=o* = o |
|     . oo*= o o  |
|      .  .       |
|        . . o E  |
|           o .   |
+----[SHA256]-----+
  • Add the public key to your GitHub account by navigating to your account settings, selecting “SSH and GPG keys”, and clicking “New SSH key”.
  • Copy the contents of the public key file (usually ~/.ssh/id_rsa.pub) and paste it into the “Key” field on the GitHub website.
  • In Visual Studio Code, open the Command Palette (press Ctrl+Shift+P on Windows) and search for Remote-SSH: Open Configuration File.
  • Select the configuration file you want to edit and add the following lines:
    Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
  • Save the file and close it.
  • Open the Command Palette again and search for Remote-SSH: Connect to Host.
  • Select the configuration file you just edited and wait for the connection to be established.
  • You should now be able to use Git with SSH authentication in Visual Studio Code.