Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nicklegan/setup-git-and-ssh-on-windows-with-github

Install and configure Git, PuTTY and SSH keys on Windows with GitHub
https://github.com/nicklegan/setup-git-and-ssh-on-windows-with-github

git-for-windows putty ssh ssh-key

Last synced: 21 days ago
JSON representation

Install and configure Git, PuTTY and SSH keys on Windows with GitHub

Awesome Lists containing this project

README

        

# Setup Git and SSH on Windows with GitHub
Install and configure Git, PuTTY and SSH keys on Windows with GitHub

## Setup overview
- [Git for Windows](#Git-for-Windows)
- [PuTTY](#PuTTY)
* [PuTTY Key Generator (puttygen.exe)](#PuTTY-Key-Generator-(puttygen.exe))
* [PuTTY Authentication Agent (pageant.exe)](#PuTTY-Authentication-Agent-(pageant.exe))
* [Plink - Command Line Connection Tool (plink.exe)](#Plink---Command-Line-Connection-Tool-(plink.exe))
- [Git global config](#Git-global-config)
- [Testing](#Testing)
- [Resources](#Resources)

## Git for Windows

- Download and install the latest [Git for Windows](https://gitforwindows.org/)

(skipped steps :point_down: can be treated having default values)

1. Select Components (default)

Screenshot 2021-04-01 at 12 51 37

2. Adjusting the default branch name for new repositories (main branch)

Screenshot 2021-04-01 at 12 56 42

3. Adjusting your PATH environment

- Git from the command line and also from 3rd party software

Screenshot 2021-04-01 at 13 07 10

4. Choosing HTTPS transport backend

Screenshot 2021-04-01 at 13 14 49

5. Configuring the line ending conversions

Screenshot 2021-04-01 at 13 16 58

6. Use MinTTY (the default terminal of MSYS2)

Screenshot 2021-04-01 at 13 20 12

7. Choose the default behavior of `git pull`

Screenshot 2021-04-01 at 13 22 49

8. Choose a credential helper

Screenshot 2021-04-01 at 13 24 36

9. Configuring extra options

Screenshot 2021-04-01 at 13 25 49

10. Configuring experimental options

Screenshot 2021-04-01 at 13 26 51

11. Completing the Git Setup Wizard

- yes, restart the computer now

Screenshot 2021-04-01 at 13 28 26

## PuTTY

1. Download and install the latest [PuTTY MSI Package installer](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) for Windows

:bulb: This package installer will also contain and automatically installs the required `plink.exe`, `pageant.exe` and `puttygen.exe` binaries required :point_down:.

2. Destination folder

Screenshot 2021-04-01 at 13 50 22

3. Product Features

Screenshot 2021-04-01 at 13 55 24

4. After the installation of PuTTY has finished, create a `.ssh` folder in your logged in user folder: `C:\Users\yourusername\.ssh\` or the equivalent `%USERPROFILE%\.ssh\`

### PuTTY Key Generator (puttygen.exe)

5. Run `puttygen.exe` either from the Start menu or the direct locaation at `C:\Program Files\PuTTY\puttygen.exe`

Screenshot 2021-04-01 at 15 18 17

6. Click `Generate`, wiggle the mouse around in the top part of the window until the progress bar is full, as the program asks you to do.

7. Enter your email address in the `Key comment` box.

8. Provide a passphrase, and repeat it in the subsequent textbox.

9. Click `Save private key`. Save the private key in the `%USERPROFILE%\.ssh\` directory created earlier. Give the private key a personal name so it can be easily identified. This file should have a `.ppk` extension.

10. In `puttygen.exe` copy the generated Public key visible under `Public key for pasting into OpenSSH authorized keys file` to your Windows clipboard (see image :point_up:).

11. Open your browser and navigate to github.com and add a new [SSH key](https://github.com/settings/ssh/new) in your account settings. Choose a key title (e.g. your email address or computer name) and paste the public SSH key data from clipboard before pressing `Add SSH key`.

Screenshot 2021-04-01 at 15 33 51

Screenshot 2021-04-01 at 15 34 38

:bulb: If you have and need command line access to GitHub Single sign-on organizations make sure you authorize your SSH key by activating [Enable SSO](https://docs.github.com/en/github/authenticating-to-github/authorizing-an-ssh-key-for-use-with-saml-single-sign-on) for the specific GitHub organizations.

### PuTTY Authentication Agent (pageant.exe)

12. To automatically run `pageant.exe` and the loaded private key at startup copy the Pageant shortcut from:

```C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PuTTY (64-bit)```

```%ProgramData%\Microsoft\Windows\Start Menu\Programs\PuTTY (64-bit)```

to

```C:\Users\your-username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup```

```%AppData%\Microsoft\Windows\Start Menu\Programs\Startup```

13. At the new Pageant shortcut startup location, right-click the Pageant shortcut and select `Properties` from the context menu.

Screenshot 2021-04-01 at 17 44 24

14. At the Pageant Properties append the path to your private key in the `Target` field and press Apply:

```"C:\Program Files\PuTTY\pageant.exe" C:\Users\your-user-name\.ssh\your-private-key.ppk```

15. Double click the Pageant shortcut file which starts Pageant and enter your private key passphrase.

Screenshot 2021-04-01 at 17 51 31

16. On the right side of the Windows taskbar Pageant should now be running, if it was already running press `Exit` and double click the newly created startup shortcut again.

Screenshot 2021-04-01 at 18 13 17

17. From the Pageant menu select `View Keys` to verify that your private key is loaded.

Screenshot 2021-04-01 at 18 21 24

## Plink - Command Line Connection Tool (plink.exe)

To automatically let Putty establish a connection for Git over SSH we have to configure Plink.

18. Nagivate to Start menu (right-click) -> System -> Advanced system settings -> Environment Variables. Add a new System Variable with the below entries:

```Variable name: GIT_SSH```

```Variable value: C:\Program Files\PuTTY\plink.exe```

Screenshot 2021-04-01 at 19 11 38

19. To verify if the environment variable is loaded run `Git Bash` from the Start menu (or via its absolute path: `C:\Program Files\Git\git-bash.exe`) and enter the following command: ` env | grep -i ssh` which should return the enabled `GIT_SSH` variable.

Screenshot 2021-04-01 at 19 29 05

## Git global config

Setup your [Git username](https://docs.github.com/en/github/getting-started-with-github/setting-your-username-in-git#setting-your-git-username-for-every-repository-on-your-computer) and [commit email address](https://docs.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address#setting-your-commit-email-address-in-git) for your system. Open a command prompt and enter the below lines, adding your personal info.

1. `git config --global user.name "First-name Last-name"`
2. `git config --global user.email [email protected]`

## Testing

1. Open a Windows command prompt and test your connection and authentication using the following command: `plink.exe -v [email protected]` the result should look like :point_down:.

Screenshot 2021-04-01 at 19 40 03

2. Now try cloning a private repository using Git over SSH, when successful the expected output should look like the image :point_down: and you will be automatically authenticated.

Screenshot 2021-04-01 at 19 51 16

Screenshot 2021-04-01 at 19 54 22

## Resources
- https://vladmihalcea.com/tutorials/git/windows-git-ssh-authentication-to-github/
- https://serverfault.com/questions/194567/how-do-i-tell-git-for-windows-where-to-find-my-private-rsa-key/850156#850156