- Git SSH Windows — пошаговое руководство
- Генерация ключа SSH
- Добавление SSH-ключа в ssh-agent
- Добавление ключа SSH в учетную запись GitHub
- Generating a new SSH key and adding it to the ssh-agent
- In this article
- Generating a new SSH key
- Adding your SSH key to the ssh-agent
- Git with SSH on Windows
- 6 Answers 6
- Getting ssh-agent to work with git run from windows command shell
- 7 Answers 7
- 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.
Generating a new SSH key and adding it to the ssh-agent
After you’ve checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.
In this article
If you don’t already have an SSH key, you must generate a new SSH key. If you’re unsure whether you already have an SSH key, check for existing keys.
If you don’t want to reenter your passphrase every time you use your SSH key, you can add your key to the SSH agent, which manages your SSH keys and remembers your passphrase.
Generating a new SSH key
Open Terminal Terminal Git Bash .
Paste the text below, substituting in your GitHub email address.
Note: If you are using a legacy system that doesn’t support the Ed25519 algorithm, use:
When you’re prompted to «Enter a file in which to save the key,» press Enter. This accepts the default file location.
At the prompt, type a secure passphrase. For more information, see «Working with SSH key passphrases».
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.
Start the ssh-agent in the background.
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.
If the file doesn’t exist, create the file.
/.ssh/config file, then modify the file, replacing
/.ssh/id_ed25519 if you are not using the default location and name for your id_ed25519 key.
Note: If you chose not to add a passphrase to your key, you should omit the UseKeychain line.
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.
Note: The -K option is Apple’s standard version of ssh-add , which 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 -K option.
If you don’t have Apple’s standard version installed, you may receive an error. For more information on resolving this error, see «Error: ssh-add: illegal option — K.»
If you have GitHub Desktop installed, you can use it to clone repositories and not deal with SSH keys.
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:
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.
Start the ssh-agent in the background.
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.
Git with SSH on Windows
I’ve went through the excellent guide provided by Tim Davis which is about configuring Git to work with SSH under Windows in order to produce a Git Server in order to have a main place for my DVCS.
I am in the process of creating a clone for my project. I’ve went through all the steps till this point, but I keep getting this from TortoiseGit:
and nothing gets cloned.
BTW: The TortoisePLink comes up just before this message appears and asks me: “ login as: ” ( I thought that this info is given in the command, i.e: Administrator@blahblah .
My home variable is set to the correct place: From a Git Bash shell:
I’ve also tried using Putty’s plink instead of TortoisePLink (in both Git’s and TortoiseGit ’s installation). This time the error was narrowed down to:
6 Answers 6
I fought with this problem for a few hours before stumbling on the obvious answer. The problem I had was I was using different ssh implementations between when I generated my keys and when I used git.
I used ssh-keygen from the command prompt to generate my keys and but when I tried «git clone ssh://. » I got the same results as you, a prompt for the password and the message «fatal: The remote end hung up unexpectedly».
Determine which ssh windows is using by executing the Windows «where» command.
The second line tells you which exact program will be executed.
Next you need to determine which ssh that git is using. Find this by:
And now you see the problem.
To correct this simply execute:
To check if changes are applied:
Now git will be able to use the keys that you generated earlier.
This fix is so far only for the current window. To fix it completely you need to change your environment variable.
- Open Windows explorer
- Right-click Computer and select Properties
- Click Advanced System Settings link on the left
- Click the Environment Variables. button
- In the system variables section select the GIT_SSH variable and press the Edit. button
- Update the variable value.
- Press OK to close all windows
Now any future command windows you open will have the correct settings.
Getting ssh-agent to work with git run from windows command shell
I have msysgit installed, with OpenSSH. I am connecting to a gitosis repo. From the git bash, I have created a .profile file that runs ssh-agent (if not already running) each time git bash is opened, using this script
I am also using git extensions, which runs the git command from the Windows command prompt, not git bash. So, ssh doesn’t see the ssh-agent that is running. Is it possible to fix this?
7 Answers 7
I had the same problem as you, then I tried adding this code
into file .bashrc in my home directory. And it works!
For msysgit you might have to modify a bit the solution offered by https://help.github.com/articles/working-with-ssh-key-passphrases
As you may notice the only change I did was in the ps call, since msysgit don’t use -U but -u
Even though you’ve probably solved it. use the eval command to make the ssh_agent process stick:
Then use ssh-add to add the keys you need.
On Windows 10 this worked for me
/.profile to open .profile
This is based on this answer. The only difference is that .bashrc did not work, instead .profile worked.
I found the smoothest way to achieve this was using Pageant as the SSH agent and plink.
You need to have a putty session configured for the hostname that is used in your remote.
You will also need plink.exe which can be downloaded from the same site as putty.
And you need Pageant running with your key loaded. I have a shortcut to pageant in my startup folder that loads my SSH key when I log in.
When you install git-scm you can then specify it to use tortoise/plink rather than OpenSSH.
The net effect is you can open git-bash whenever you like and push/pull without being challenged for passphrases.
Same applies with putty and WinSCP sessions when pageant has your key loaded. It makes life a hell of a lot easier (and secure).
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 :