- Git SSH Windows — пошаговое руководство
- Генерация ключа SSH
- Добавление SSH-ключа в ssh-agent
- Добавление ключа SSH в учетную запись GitHub
- dmangiarelli / GitForWindowsSetup.md
- bsara / git-ssh-auth-win-setup.md
- This comment has been minimized.
- pensebien commented Nov 28, 2017 •
- This comment has been minimized.
- rianquinn commented Feb 27, 2018
- This comment has been minimized.
- leoreeves commented Mar 6, 2018 •
- This comment has been minimized.
- pauljohn32 commented Mar 18, 2018
- This comment has been minimized.
- smutel commented Mar 22, 2018
- This comment has been minimized.
- gregbown commented May 14, 2018
- This comment has been minimized.
- demiters commented Aug 27, 2018
- This comment has been minimized.
- fushenghua commented Sep 4, 2018
- This comment has been minimized.
- bonovski commented Sep 13, 2018
- This comment has been minimized.
- surjikal commented Sep 15, 2018
- This comment has been minimized.
- Tri125 commented Jan 2, 2019
Git SSH Windows — пошаговое руководство
Настроим пошагово Git SSH для Windows 10. Это позволит вам выполнять команды git без ввода пароля от своей учетной записи GitHub.
- Генерация ключа SSH.
- Добавление SSH-ключа в ssh-agent.
- Добавление ключа SSH в учетную запись GitHub.
Генерация ключа SSH
Откройте bash/терминал . Добавьте следующий текст, подставив свой адрес электронной почты GitHub .
Будет создан ключ ssh , используя e-mail в качестве метки.
Когда вам будет предложено «Введите файл, в котором вы хотите сохранить ключ», нажмите Enter . Это установит в местоположение по умолчанию.
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
Далее введите безопасную фразу-пароль дважды или просто нажмите Enter .
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Добавление SSH-ключа в ssh-agent
Чтобы запустить ssh-агент введите следующую команду.
На экране отобразится похожая строка.
Agent pid 31724
Добавим свой закрытый ключ SSH в ssh-agent . Если вы создали свой ключ с другим именем (или добавляете существующий ключ с другим именем), замените в команде id_rsa на имя вашего файла закрытого (приватного) ключа.
Ключ будет успешно добавлен в ssh-агент .
Добавление ключа SSH в учетную запись GitHub
Мы сгенерировали у себя на компьютере закрытый ключ SSH и добавили его в ssh-агент . Теперь нам необходимо добавить SSH ключ в учетную запись GitHub.
Сейчас нам необходимо скопировать SSH ключ в буфер обмена.
Способов есть несколько, но я же вам предлагаю следующее решения для Windows 10: введите команду ниже.
Прямо в терминале вы увидите содержимое необходимого файла с ключем. Скопируйте его в буфер.
Теперь зайдите на вашу страницу GitHub » Settings .
Перейдите во вкладку SSH and GPG keys и нажмите на кнопку New SSH key для добавления SSH ключа в вашу учетную запись GitHub.
В поле Title добавьте заголок для данного ключа. Например, если вы захотите настроить SSH доступ на нескольких устройствах, то вы будите понимать какой ключ принадлежит какому устройству.
В поле Key добавьте свой ssh-ключ, который вы скопировали в буфер обмена на предыдущем шаге.
Нажмите Add SSH key .
Для подтверждения вам потребуется ввести свой пароль от учетной записи GitHub .
На этом настройка SSH для вашего устройства завершена, теперь вы можете работать с git без ввода пароля от своей учетной записи.
Если вам понравилась данная статья, можете прочитать как настроить моментальную загрузку сайта на хостинг и синхронизацию файлов.
Надеюсь, вам понравилась данная информация. Если вам интересна тема web-разработки, то можете следить за выходом новых статей в Telegram.
dmangiarelli / GitForWindowsSetup.md
How to setup Git for Windows
I know this document seems long, but it shouldn’t be too difficult to follow. This guide is based on Windows, but every program here has Linux/Mac equivalents, and in most cases they’re built-in. So, take a deep breath and go step by step.
The steps below are for GitHub, but the steps are almost idential for Bitbucket, Heroku, etc.
You’ll probably want to make sure Chocolatey is installed, since it streamlines installing this stuff later. If you install via Chocolatey, you don’t need to run the installers from the products’ respective sites.
The first thing you’ll want to do is to download and install Cmder, which is a terminal program that serves as excellent replacement for the built-in cmd.exe . It’s not a shell itself, so it supports running plain old cmd.exe commands and running PowerShell.
As a comment notes below, Cmder is actually a packaged version of ConEmu. If you don’t want the out-of-the-box configuration that Cmder comes with, you can install ConEmu by iteslf and customize it to your needs from there. Both of course have the same features though.
With Chocolatey, run one of the following from an elevated propt:
Git uses a per-user config file located at %USERPROFILE%\.gitconfig . It’s a plain-text file you can edit with your favorite text editor (or Notepad, if you haven’t chosen a favorite yet). Note that git calls this config the «global» config. It’s more general than per-repository config, and more specific than the machine config.
This is optional, but highly recommended. Download and install TortoiseGit. You’ll want some of the tools it installs later. If you have another Tortoise installed (e.g. TortoiseSVN) and you don’t want to have TortoiseGit’s context menu clutter, you don’t have to download it. If you’re not sure, get it. TortoiseGit is nice because it adds overlay icons (that don’t always update properly). Another benefit is that a full PuTTY install, which you’ll also need.
If you really don’t want the extra shell extension (I don’t blame you), you can install TortoiseGit, copy TortoiseGitPlink.exe from TortoiseGit’s bin/ directory, store it somewhere else, and then uninstall TortoiseGit. Then, later on when you set the GIT_SSH environment variable, just use the new path to it.
You can skip this step if you installed TortoiseGit.
If you didn’t install it, download and run the Windows Installer so you get all the apps installed from one package.
There are a few different ways to authenticate with GitHub. The easiest is to use Git Credential Manager for Windows. It supports authenticating with GitHub over HTTPS even with two factor authentication. If you use this, you can skip to the «Install Git» section. If you wan to use SSH, read on.
SSH Setup with PuTTY
If you’re using a service like GitHub or Bitbucket, you have a couple of options when authenticating so you can push your code. This will allow you to share your code with other people. Even if you’re the only person working on a project, those sites can serve as a backup.
Set up SSH keys on Windows:
- Open PuTTYgen by searching for it in the Start menu or Start screen. If you see multiple entries, any will work.
Leave the settings as they are, unless you know what you’re doing. - 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.
- Once you’ve provided enough entropy, a bunch of text fields will appear. It’s highly recommended that you provide a passphrase.
- After providing a passphrase, click «Save private key». The usual directory to save these in is %USERPROFILE%\_ssh .
It doesn’t matter what you call the key, but for demonstration purposes, I’m going to call it github.ppk . This file should have an extension of .ppk . - Now, log in to GitHub.com. Don’t close PuTTYgen yet.
- Go to your Account settings and then to SSH keys.
- Click «Add SSH key». Copy the text in the top text box in PuTTYgen, the one labeled «Public key for pasting into OpenSSH authorized_keys file» and paste it into the Key box in GitHub. Give it a title that describes what machine the key is on (e.g. «Work laptop»).
- Click «Add key».
And with that, we’re done setting things up to connect to GitHub.
If you also want a native command-line build of ssh (i.e., ssh.exe or ssh-agent.exe ) to work, you’ll need to also export your key in OpenSSH format. You can do this from PuTTYgen by clicking on Conversions > Export OpenSSH Key. These keys are typically saved in %USERPROFILE%\.ssh or (
/.ssh in *nix-style paths, which also work in Bash environments on Windows). Once you export the key, you should copy it to %USERPROFILE%\.ssh\id_rsa . See the comments for some more information. Source
Now your SSH keys are set up and you can use them to push to and pull from GitHub, but you still need to do one more thing to use those keys. Before you want to push code to GitHub, you’ll need to do this, but once you do it, you won’t have to do it again until you restart your computer.
- Run Pageant (search for it in the Start menu/screen).
- Right-click the Notification Area icon (it looks like a PC with a dark sombrero).
- Click «Add Key».
- Find the .ppk file you created above.
- Enter the passphrase you used before.
If the passphrase prompt goes away, you should be all set.
If you want to confirm, right-click on the Pageant icon again and click on «View Keys».
Now, you can pull from and push to GitHub without being pestered for your password, at least until you log off. You can also double-click on the notification area icon to see what keys have already been added to Pageant.
Git for Windows
Finally, we get to the part where we get to install Git.
- Download the Git installer.
Or, with Chocolatey (which may be a patch or two behind the main site, and will always install the shell extension).
choco install git - When installing, pick the following options:
- Uncheck the box for Windows Explorer integration.
- Choose «Run Git from the Windows Command Prompt».
- Choose «Checkout Windows-style, commit Unix-style line endings».
- Let the installer finish.
You may need to manually add a System Environment Variable (Start > Search for «Edit the system environment variables»). Add a new System (not User) variable. Give it the name GIT_SSH , and a value of the path to a TortoiseGitPlink.exe (e.g. C:\Program Files\TortoiseGit\bin\TortoisePLink.exe ).
Or, the PowerShell way (run from an elevated PowerShell prompt): [Environment]::SetEnvironmentVariable(«GIT_SSH», «C:\Program Files\TortoiseGit\bin\TortoiseGitPLink.exe», «Machine» )
This is mostly optional if you’re using Cmder, but if you want more general support for Git in PowerShell, you can install an awesome package called posh-git. Because PowerShell is awesome, and you should be using it instead of batch scripts and plain old cmd.exe as much as you can. Even without this, you can use Git commands from PowerShell, but posh-git will give you status information right in the prompt.
- Make sure you have PowerShell 5 or later installed.
To check, open PowerShell from your Start menu/screen and type $PSVersionTable . The PSVersion value should be 5.0 or greater.
If you don’t have v5 or later installed, download and run the correct installer for Windows Management Framework 5 (which comes with PowerShell 5) from this page. - Change PowerShell’s script execution policy.
Open an elevated PowerShell prompt and enter:
Set-ExecutionPolicy RemoteSigned - Install Posh-Git.
Install-Module Posh-Git
Now, whenever you’re in a Git workspace directory in your PowerShell prompt, you’ll get a fancy prompt, and you can still use tab completion and standard Windows paths. Hooray! Git will still echo paths with backslashes, but it will recognize forward slashes.
- Git Extensions is another shell extension that also has a Visual Studio extension. It’s very user-friendly.
- GitHub Desktop, not to be confused with Git for Windows, is GitHub’s Windows Git client.
- SourceTree is to Bitbucket as GitHub for Windows is to GitHub: it’s Atlassian’s answer to GitHub for Windows.
A difftool is installed by default with TortoiseGit, but I’m a fan of using SourceGear DiffMerge for diffs and P4Merge for merging. These may be installed via Chocolatey with choco install diffmerge p4merge . Install those programs and add the following to your .gitconfig file:
bsara / git-ssh-auth-win-setup.md
Setup SSH Authentication for Git Bash on Windows
- Create a folder at the root of your user home folder (Example: C:/Users/uname/ ) called .ssh .
- Create the following files if they do not already exist (paths begin from the root of your user home folder):
- .ssh/config
- .bash_profile
- .bashrc
Create a New SSH Key
Follow the steps in the section named «Generating a new SSH Key» found in the following documentation from GitHub: Generating a new SSH key and adding it to the ssh-agent
Configure SSH for Git Hosting Server
Add the following text to .ssh/config ( .ssh should be found in the root of your user home folder):
Enable SSH Agent Startup Whenever Git Bash is Started
First, ensure that following lines are added to .bash_profile , which should be found in your root user home folder:
Now, add the following text to .bashrc , which should be found in your root user home folder:
This comment has been minimized.
Copy link Quote reply
pensebien commented Nov 28, 2017 •
Thank you for the gist. But I found it easy to just add to my
./profile file
localUser@mycomputer MINGw64 / notepad /.profile
then I Paste this
I also took time to read about ssh-agent
This comment has been minimized.
Copy link Quote reply
rianquinn commented Feb 27, 2018
This worked perfectly, Thanks
This comment has been minimized.
Copy link Quote reply
leoreeves commented Mar 6, 2018 •
@emmaakin, thanks that works great. FYI, there’s a backtick at the start and end your code snippet that will cause an error.
This comment has been minimized.
Copy link Quote reply
pauljohn32 commented Mar 18, 2018
The part that launches the ssh agent is valuable. However, I’m not persuaded there is a benefit in the git config file. The Default key name is «id_rsa» and that is what ssh will look for. I think the config file is not having an effect. At least for me.
In my case, the name of the key is different for every server and, for reasons I cannot understand, the ssh system only wants to look for «id_rsa». On Linux, this is a symptom of a permissions problem, permissions should be 700. But in Windows, it appears not possible to set permissions at all. In the Git bash shell, permissions always have g+r and o+r.
The config file is ignores, at least for me. You can see same result if you name your key in another file, put in
And it wont work. If it does work, I’d love to hear from you.
This comment has been minimized.
Copy link Quote reply
smutel commented Mar 22, 2018
If you use an old dsa key, put this in config PubkeyAcceptedKeyTypes=+ssh-dss
This comment has been minimized.
Copy link Quote reply
gregbown commented May 14, 2018
Wow! First of all, thank you! I am astonished as to why none of this presented anywhere on GitHub? I spent a couple of hours looking for the missing steps, All they say is paste your public key here with no mention of how GitHub is supposed to find the private key on Windows, where it should be stored, what else is required, etc.
The only thing I would add to this is that if you are generating you keys with PuTTY Key Generator, you must select from the menu -> Conversions -> Export SSH key(force new file format) and save the private key as just «id_rsa» NOT id_rsa.ppk the default PuTTY format
Thank you again Brandon
This comment has been minimized.
Copy link Quote reply
demiters commented Aug 27, 2018
This comment has been minimized.
Copy link Quote reply
fushenghua commented Sep 4, 2018
This comment has been minimized.
Copy link Quote reply
bonovski commented Sep 13, 2018
Thank you, works perfectly!
bitbucket and github are really missing these crucial steps, lost almost 8 hours setting it up on windows.
This comment has been minimized.
Copy link Quote reply
surjikal commented Sep 15, 2018
I added this to /etc/ssh/ssh_config so that I could use a shared deployment key for all users on my server. Thanks for the info!
This comment has been minimized.
Copy link Quote reply
Tri125 commented Jan 2, 2019
If you want to add multiple keys to the agent simply replace the line ssh-add
/.ssh/id_rsa; with the following block:
This will add every ssh key that start with id_
The inconvenience is that when the ssh-agent start, it’s going to prompt you to enter the password for every keys even if you don’t necessarily use them. I haven’t found a solution for this.
You might want to use that with git for windows if, say, you have a different github account: 1 for your personal work and another for your professional work. Github won’t let you re-use the same ssh key for both accounts so you need 2 keys.
To make this work, you will need to do 2 more steps. in $
In this example, we have the secondary ssh key named id_rsa_corpo .
If you already cloned the repo for the secondary key, change the remote to point to github-corpo .
If not, then just clone by replacing the host :