Windows generate ssh key for git

Chapters ▾

Chapters ▾

  1. 1. Getting Started

    1. 1.1
      About Version Control
    2. 1.2
      A Short History of Git
    3. 1.3
      What is Git?
    4. 1.4
      The Command Line
    5. 1.5
      Installing Git
    6. 1.6
      First-Time Git Setup
    7. 1.7
      Getting Help
    8. 1.8
      Summary
  2. 2. Git Basics

    1. 2.1
      Getting a Git Repository
    2. 2.2
      Recording Changes to the Repository
    3. 2.3
      Viewing the Commit History
    4. 2.4
      Undoing Things
    5. 2.5
      Working with Remotes
    6. 2.6
      Tagging
    7. 2.7
      Git Aliases
    8. 2.8
      Summary
  3. 3. Git Branching

    1. 3.1
      Branches in a Nutshell
    2. 3.2
      Basic Branching and Merging
    3. 3.3
      Branch Management
    4. 3.4
      Branching Workflows
    5. 3.5
      Remote Branches
    6. 3.6
      Rebasing
    7. 3.7
      Summary
  4. 4. Git on the Server

    1. 4.1
      The Protocols
    2. 4.2
      Getting Git on a Server
    3. 4.3
      Generating Your SSH Public Key
    4. 4.4
      Setting Up the Server
    5. 4.5
      Git Daemon
    6. 4.6
      Smart HTTP
    7. 4.7
      GitWeb
    8. 4.8
      GitLab
    9. 4.9
      Third Party Hosted Options
    10. 4.10
      Summary
  5. 5. Distributed Git

    1. 5.1
      Distributed Workflows
    2. 5.2
      Contributing to a Project
    3. 5.3
      Maintaining a Project
    4. 5.4
      Summary
  1. 6. GitHub

    1. 6.1
      Account Setup and Configuration
    2. 6.2
      Contributing to a Project
    3. 6.3
      Maintaining a Project
    4. 6.4
      Managing an organization
    5. 6.5
      Scripting GitHub
    6. 6.6
      Summary
  2. 7. Git Tools

    1. 7.1
      Revision Selection
    2. 7.2
      Interactive Staging
    3. 7.3
      Stashing and Cleaning
    4. 7.4
      Signing Your Work
    5. 7.5
      Searching
    6. 7.6
      Rewriting History
    7. 7.7
      Reset Demystified
    8. 7.8
      Advanced Merging
    9. 7.9
      Rerere
    10. 7.10
      Debugging with Git
    11. 7.11
      Submodules
    12. 7.12
      Bundling
    13. 7.13
      Replace
    14. 7.14
      Credential Storage
    15. 7.15
      Summary
  3. 8. Customizing Git

    1. 8.1
      Git Configuration
    2. 8.2
      Git Attributes
    3. 8.3
      Git Hooks
    4. 8.4
      An Example Git-Enforced Policy
    5. 8.5
      Summary
  4. 9. Git and Other Systems

    1. 9.1
      Git as a Client
    2. 9.2
      Migrating to Git
    3. 9.3
      Summary
  5. 10. Git Internals

    1. 10.1
      Plumbing and Porcelain
    2. 10.2
      Git Objects
    3. 10.3
      Git References
    4. 10.4
      Packfiles
    5. 10.5
      The Refspec
    6. 10.6
      Transfer Protocols
    7. 10.7
      Maintenance and Data Recovery
    8. 10.8
      Environment Variables
    9. 10.9
      Summary
  1. A1. Appendix A: Git in Other Environments

    1. A1.1
      Graphical Interfaces
    2. A1.2
      Git in Visual Studio
    3. A1.3
      Git in Visual Studio Code
    4. A1.4
      Git in IntelliJ / PyCharm / WebStorm / PhpStorm / RubyMine
    5. A1.5
      Git in Sublime Text
    6. A1.6
      Git in Bash
    7. A1.7
      Git in Zsh
    8. A1.8
      Git in PowerShell
    9. A1.9
      Summary
  2. A2. Appendix B: Embedding Git in your Applications

    1. A2.1
      Command-line Git
    2. A2.2
      Libgit2
    3. A2.3
      JGit
    4. A2.4
      go-git
    5. A2.5
      Dulwich
  3. A3. Appendix C: Git Commands

    1. A3.1
      Setup and Config
    2. A3.2
      Getting and Creating Projects
    3. A3.3
      Basic Snapshotting
    4. A3.4
      Branching and Merging
    5. A3.5
      Sharing and Updating Projects
    6. A3.6
      Inspection and Comparison
    7. A3.7
      Debugging
    8. A3.8
      Patching
    9. A3.9
      Email
    10. A3.10
      External Systems
    11. A3.11
      Administration
    12. A3.12
      Plumbing Commands


2nd Edition

4.3 Git on the Server — Generating Your SSH Public Key

Many Git servers authenticate using SSH public keys.
In order to provide a public key, each user in your system must generate one if they don’t already have one.
This process is similar across all operating systems.
First, you should check to make sure you don’t already have a key.
By default, a user’s SSH keys are stored in that user’s ~/.ssh directory.
You can easily check to see if you have a key already by going to that directory and listing the contents:

$ cd ~/.ssh
$ ls
authorized_keys2  id_dsa       known_hosts
config            id_dsa.pub

You’re looking for a pair of files named something like id_dsa or id_rsa and a matching file with a .pub extension.
The .pub file is your public key, and the other file is the corresponding private key.
If you don’t have these files (or you don’t even have a .ssh directory), you can create them by running a program called ssh-keygen, which is provided with the SSH package on Linux/macOS systems and comes with Git for Windows:

$ ssh-keygen -o
Generating public/private rsa key pair.
Enter file in which to save the key (/home/schacon/.ssh/id_rsa):
Created directory '/home/schacon/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/schacon/.ssh/id_rsa.
Your public key has been saved in /home/schacon/.ssh/id_rsa.pub.
The key fingerprint is:
d0:82:24:8e:d7:f1:bb:9b:33:53:96:93:49:da:9b:e3 schacon@mylaptop.local

First it confirms where you want to save the key (.ssh/id_rsa), and then it asks twice for a passphrase, which you can leave empty if you don’t want to type a password when you use the key.
However, if you do use a password, make sure to add the -o option; it saves the private key in a format that is more resistant to brute-force password cracking than is the default format.
You can also use the ssh-agent tool to prevent having to enter the password each time.

Now, each user that does this has to send their public key to you or whoever is administrating the Git server (assuming you’re using an SSH server setup that requires public keys).
All they have to do is copy the contents of the .pub file and email it.
The public keys look something like this:

$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSU
GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3
Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XA
t3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/En
mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx
NrRFi9wrf+M7Q== schacon@mylaptop.local

About SSH key passphrases

You can access and write data in repositories on GitHub.com using SSH (Secure Shell Protocol). When you connect via SSH, you authenticate using a private key file on your local machine. For more information, see «About SSH.»

When you generate an SSH key, you can add a passphrase to further secure the key. Whenever you use the key, you must enter the passphrase. If your key has a passphrase and you don’t want to enter the passphrase every time you use the key, you can add your key to the SSH agent. The SSH agent manages your SSH keys and remembers your passphrase.

If you don’t already have an SSH key, you must generate a new SSH key to use for authentication. If you’re unsure whether you already have an SSH key, you can check for existing keys. For more information, see «Checking for existing SSH keys.»

If you want to use a hardware security key to authenticate to GitHub, you must generate a new SSH key for your hardware security key. You must connect your hardware security key to your computer when you authenticate with the key pair. For more information, see the OpenSSH 8.2 release notes.

Generating a new SSH key

You can generate a new SSH key on your local machine. After you generate the key, you can add the key to your account on GitHub.com to enable authentication for Git operations over SSH.

Note: GitHub improved security by dropping older, insecure key types on March 15, 2022.

As of that date, DSA keys (ssh-dss) are no longer supported. You cannot add new DSA keys to your personal account on GitHub.com.

RSA keys (ssh-rsa) with a valid_after before November 2, 2021 may continue to use any signature algorithm. RSA keys generated after that date must use a SHA-2 signature algorithm. Some older clients may need to be upgraded in order to use SHA-2 signatures.

  1. Open TerminalTerminalGit Bash.

  2. Paste the text below, substituting in your GitHub email address.

    $ ssh-keygen -t ed25519 -C "your_email@example.com"

    Note: If you are using a legacy system that doesn’t support the Ed25519 algorithm, use:

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

    This creates a new SSH key, using the provided email as a label.

    > Generating public/private ALGORITHM key pair.

    When you’re prompted to «Enter a file in which to save the key», you can press Enter to accept the default file location. Please note that if you created SSH keys previously, ssh-keygen may ask you to rewrite another key, in which case we recommend creating a custom-named SSH key. To do so, type the default file location and replace id_ssh_keyname with your custom key name.

    > Enter a file in which to save the key (/Users/YOU/.ssh/id_ALGORITHM: [Press enter]

    > Enter a file in which to save the key (/c/Users/YOU/.ssh/id_ALGORITHM):[Press enter]

    > Enter a file in which to save the key (/home/YOU/.ssh/ALGORITHM):[Press enter]

  3. At the prompt, type a secure passphrase. For more information, see «Working with SSH key passphrases.»

    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]

Adding your SSH key to the ssh-agent

Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key. When adding your SSH key to the agent, use the default macOS ssh-add command, and not an application installed by macports, homebrew, or some other external source.

  1. Start the ssh-agent in the background.

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566

    Depending on your environment, you may need to use a different command. For example, you may need to use root access by running sudo -s -H before starting the ssh-agent, or you may need to use exec ssh-agent bash or exec ssh-agent zsh to run the ssh-agent.

  2. If you’re using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.

    • First, check to see if your ~/.ssh/config file exists in the default location.

      $ open ~/.ssh/config
      > The file /Users/YOU/.ssh/config does not exist.
    • If the file doesn’t exist, create the file.

      $ touch ~/.ssh/config
    • Open your ~/.ssh/config file, then modify the file to contain the following lines. If your SSH key file has a different name or path than the example code, modify the filename or path to match your current setup.

      Host *.github.com
        AddKeysToAgent yes
        UseKeychain yes
        IdentityFile ~/.ssh/id_ed25519
      

      Notes:

      • If you chose not to add a passphrase to your key, you should omit the UseKeychain line.

      • If you see a Bad configuration option: usekeychain error, add an additional line to the configuration’s’ Host *.github.com section.

        Host *.github.com
          IgnoreUnknown UseKeychain
        
  3. Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

    $ ssh-add --apple-use-keychain ~/.ssh/id_ed25519

    Note: The --apple-use-keychain option stores the passphrase in your keychain for you when you add an SSH key to the ssh-agent. If you chose not to add a passphrase to your key, run the command without the --apple-use-keychain option.

    The --apple-use-keychain option is in Apple’s standard version of ssh-add. In MacOS versions prior to Monterey (12.0), the --apple-use-keychain and --apple-load-keychain flags used the syntax -K and -A, respectively.

    If you don’t have Apple’s standard version of ssh-add installed, you may receive an error. For more information, see «Error: ssh-add: illegal option — K.»

  4. Add the SSH key to your account on GitHub. For more information, see «Adding a new SSH key to your GitHub account.»

If you have GitHub Desktop installed, you can use it to clone repositories and not deal with SSH keys.

  1. Ensure the ssh-agent is running. You can use the «Auto-launching the ssh-agent» instructions in «Working with SSH key passphrases», or start it manually:

    # start the ssh-agent in the background
    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
  2. Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

    $ ssh-add ~/.ssh/id_ed25519
  3. Add the SSH key to your account on GitHub. For more information, see «Adding a new SSH key to your GitHub account.»

  1. Start the ssh-agent in the background.

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566

    Depending on your environment, you may need to use a different command. For example, you may need to use root access by running sudo -s -H before starting the ssh-agent, or you may need to use exec ssh-agent bash or exec ssh-agent zsh to run the ssh-agent.

  2. Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

    $ ssh-add ~/.ssh/id_ed25519
  3. Add the SSH key to your account on GitHub. For more information, see «Adding a new SSH key to your GitHub account.»

Generating a new SSH key for a hardware security key

If you are using macOS or Linux, you may need to update your SSH client or install a new SSH client prior to generating a new SSH key. For more information, see «Error: Unknown key type.»

  1. Insert your hardware security key into your computer.

  2. Open TerminalTerminalGit Bash.

  3. Paste the text below, substituting in the email address for your account on GitHub.

    $ ssh-keygen -t ed25519-sk -C "YOUR_EMAIL"

    Note: If the command fails and you receive the error invalid format or feature not supported, you may be using a hardware security key that does not support the Ed25519 algorithm. Enter the following command instead.

    $ ssh-keygen -t ecdsa-sk -C "your_email@example.com"
  4. When you are prompted, touch the button on your hardware security key.

  5. When you are prompted to «Enter a file in which to save the key,» press Enter to accept the default file location.

    > Enter a file in which to save the key (/Users/YOU/.ssh/id_ed25519_sk): [Press enter]
    > Enter a file in which to save the key (/c/Users/YOU/.ssh/id_ed25519_sk):[Press enter]
    > Enter a file in which to save the key (/home/YOU/.ssh/id_ed25519_sk):[Press enter]
  6. When you are prompted to type a passphrase, press Enter.

    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]
  7. Add the SSH key to your account on GitHub. For more information, see «Adding a new SSH key to your GitHub account.»

key

What is a Git SSH Key?

An SSH key is an access credential for the SSH (secure shell) network protocol. This authenticated and encrypted secure network protocol is used for remote communication between machines on an unsecured open network. SSH is used for remote file transfer, network management, and remote operating system access. The SSH acronym is also used to describe a set of tools used to interact with the SSH protocol.

SSH uses a pair of keys to initiate a secure handshake between remote parties. The key pair contains a public and private key. The private vs public nomenclature can be confusing as they are both called keys. It is more helpful to think of the public key as a «lock» and the private key as the «key». You give the public ‘lock’ to remote parties to encrypt or ‘lock’ data. This data is then opened with the ‘private’ key which you hold in a secure place.

How to Create an SSH Key

SSH keys are generated through a public key cryptographic algorithm, the most common being RSA or DSA. At a very high level SSH keys are generated through a mathematical formula that takes 2 prime numbers and a random seed variable to output the public and private key. This is a one-way formula that ensures the public key can be derived from the private key but the private key cannot be derived from the public key.

SSH keys are created using a key generation tool. The SSH command line tool suite includes a keygen tool. Most git hosting providers offer guides on how to create an SSH Key.

Generate an SSH Key on Mac and Linux

Both OsX and Linux operating systems have comprehensive modern terminal applications that ship with the SSH suite installed. The process for creating an SSH key is the same between them.

1. execute the following to begin the key creation

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

This command will create a new SSH key using the email as a label

2. You will then be prompted to «Enter a file in which to save the key.»
You can specify a file location or press “Enter” to accept the default file location.

> Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

3. The next prompt will ask for a secure passphrase.
A passphrase will add an additional layer of security to the SSH and will be required anytime the SSH key is used. If someone gains access to the computer that private keys are stored on, they could also gain access to any system that uses that key. Adding a passphrase to keys will prevent this scenario.

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

At this point, a new SSH key will have been generated at the previously specified file path.

4. Add the new SSH key to the ssh-agent

The ssh-agent is another program that is part of the SSH toolsuite. The ssh-agent is responsible for holding private keys. Think of it like a keychain. In addition to holding private keys it also brokers requests to sign SSH requests with the private keys so that private keys are never passed around unsecurly.

Before adding the new SSH key to the ssh-agent first ensure the ssh-agent is running by executing:

$ eval "$(ssh-agent -s)"
> Agent pid 59566

Once the ssh-agent is running the following command will add the new SSH key to the local SSH agent.

ssh-add -K /Users/you/.ssh/id_rsa

The new SSH key is now registered and ready to use!

Generate an SSH Key on Windows

Windows environments do not have a standard default unix shell. External shell programs will need to be installed for to have a complete keygen experience. The most straight forward option is to utilize Git Bash. Once Git Bash is installed the same steps for Linux and Mac can be followed within the Git Bash shell.

Windows Linux Subsystem

Modern windows environments offer a windows linux subsystem. The windows linux subsystem offers a full linux shell within a traditional windows environment. If a linux subsystem is available the same steps previously discussed for Linux and Mac can be followed with in the windows linux subsystem.

Summary

SSH keys are used to authenticate secure connections. Following this guide, you will be able to create and start using an SSH key. Git is capable of using SSH keys instead of traditional  password authentication when pushing or pulling to remote repositories. Modern hosted git solutions like Bitbucket support SSH key authentication.

A SSH key is considered an access credential for the secure shell (SSH) network protocol. It is an encrypted and authenticated secure network protocol, applied for remote communication between machines operating on an unsecured network.
This snippet will help you to find the kbd class=»highlighted»>SSH key on your PC if it exists, generate a new SSH key and learn how to add it to your ssh-agent or your GitHub/Bitbucket account.

You can do that by following the steps below. Type ls -al ~/.ssh so as to see your ssh keys:

By default, the filename of the public key is one of the following:

  id_ecdsa.pub
  id_ed25519.pub
  id_rsa.pub

If you don’t have an SSH key, you should create it. Now let’s generate a new SSH key step by step.

Type the command below, using your GitHub’s account email:

ssh-keygen -t rsa -b 4096 -C "[your github's email]"

After running this command, you will be offered to set the SSH key path, but we recommend you to use its default value by pressing the «Enter» button.

> Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

After that it will offer you to insert a passphrase to protect your SSH key.

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

Now, when you already have an SSH key, you can add it into the ssh-agent.

  1. Be sure ssh-agent is enabled:
  2. Add your SSH key to the ssh-agent.

    If you changed the default path while generating an SSH key, now you need to mention that path instead of ~/.ssh/id_rsa.

Usually, repositories are private, and the developers are required to write a username and a password to take any actions related to the remote repository. Adding your SSH key to the GitHub/Bitbucket account helps the system to identify you and your are not asked to write your username and password each time.

Open your terminal and type the command below:

Now, it will print the SSH key in the terminal, so you can copy it.

How to Add SSH Key to the GitHub Account

  1. Log into your GitHub’s account. In the top right corner of any page, click your profile photo, then click Settings.
  2. In the user settings sidebar, click on SSH and GPG keys.
  3. Click on the New SSH key button.
  4. Type the title and your SSH key, and press the Add SSH key button.

How to Add SSH Key to the Bitbucket Account

  1. Log into your Bitbucket’s account. In the left bottom corner of any page, click your profile photo, then click Personal Settings.
  2. In the Personal settings sidebar, click on SSH keys.
  3. Click on the Add key button.
  4. Type the title and your Add key, and press the Add key button.

Now you have added your PC’s SSH key to your GitHub’s/Bitbucket’s account.

SSH keys are an access credential used in SSH protocol (Secure Shell) which is a network protocol that helps to login from one computer to another securely, as well as to manage networks, operating systems, and configurations. If you use Git and want to clone anything from remote repositories, you have to choose one of these two ways: HTTPS or SSH. If you use HTTPS, you have to type your account access every time you communicate with the remote repository, or change your configs and fill your account data (access). Another modern way is to use the SSH authentication method. It is used in many Version Control Systems to have command line access into your servers, etc. SSH key pairs can be used for authentication instead of passwords. Each key pair consists of a private key and a corresponding public key. When you use SSH key for Git, you inform Git that this PC is authenticated for that GitHub account, and it will never ask you about any access again because you have already given it your SSH key.

Like this post? Please share to your friends:
  • Windows ink workspace скачать для windows 10
  • Windows holographic devices что это за папка windows 10
  • Windows information protection wip 4 5
  • Windows hlds update tool cs source скачать
  • Windows imaging для windows xp 32 bit скачать бесплатно