Git github ssh windows

Работа c GitHub по SSH под Windows 10

Git умеет работать с четырьмя сетевыми протоколами для передачи данных: локальный, Secure Shell (SSH), Git и HTTP. Положительным аспектом использования протокола HTTP(S) является простота настройки. Поэтому при работе с GitHub он используется чаще всего.

Как настроить работу с репозиторием на GitHub.com по SSH под Windows 10? Для начала посмотрим, какие ssh-ключи уже есть в системе:

Ключей еще нет, директория пуста. Сгенерируем ключи командой

Сначала необходимо указать расположение файла для сохранения ключа. Просто жмем Enter, чтобы сохранить ключ в файле по умолчанию (

/.ssh/id_rsa ). Затем надо дважды ввести пароль (который можно оставить пустым, чтобы не вводить каждый раз).

Теперь добавим сгенерированный ключ в свой SSH-агент. Включаем SSH-агент командой

Добавляем в него ключ

Теперь надо добавить наш ключ в аккаунте GitHub. Авторизуемся и переходим на страницу https://github.com/settings/keys, жмем кнопку «New SSH key» и вставляем содержимое файла

/.ssh/id_rsa в текстовое поле «Key».

Теперь можно использовать SSH вместо HTTPS. Смотрим, какой должна быть ссылка проекта на GitHub, предварительно выбрав «Use SSH» (вместо «Use HTTPS»):

И выполняем команду:

Чтобы не вводить каждый раз пароль при работе с репозиторием на GitHub, нужно создать файл C:/Users/UserName/.bashrc и добавить туда следующее:

Теперь запрос пароля будет происходить только один раз, при запуске (каждой новой) консоли.

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

Читайте также:  Как открыть инсталлятор windows 10

/.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.

cham11ng / git-ssh-configuration.md

Git Installation and SSH Configuration

Installation

We can check if Git is installed by typing git —version in your Terminal or Git Bash (Windows) respectively.

Download Git for Windows from this link https://git-scm.com/downloads

Configuration

Set up SSH for Git

Open your Terminal or Git Bash(Windows).

  • Ensure we have SSH client installed:

List the contents of your

If we have already setup default identity, we can see two id_ files

  • Set up our default identity:

The system adds keys for all identities to the /home/ /.ssh (Linux) or /c/Users/ /.ssh (Windows) directory. The following procedure creates a default identity.

Hit ssh-keygen command on Terminal or Git Bash.

Press enter to accept the default key and location or we can set somewhere else.

We enter and re-enter a passphrase when prompted. Unless you need a key for a process such as script, you should always provide a passphrase. The command creates your default identity with its public and private keys

List the contents of your

  • Adding your SSH key to the ssh-agent:

Ensure ssh-agent is enabled:

Add your SSH key to the ssh-agent

  • Find and take a note of your public key fingerprint. If you’re using OpenSSH 6.7 or older:
  • Install the public key on your Remote GitHub/Bitbucket account:

Copy this output to respective SSH keys setting.

  • GitHub Setting >> SSH and GPG keys >> New SSH key
  • Bitbucket Setting >> SSH keys >> Add Key

You have now successfully configured SSH for Git in Windows/Linux/Mac OS.

Adding a new SSH key to your GitHub account

To configure your GitHub account to use your new (or existing) SSH key, you’ll also need to add it to your GitHub account.

Before adding a new SSH key to your GitHub account, you should have:

After adding a new SSH key to your GitHub account, you can reconfigure any local repositories to use SSH. For more information, see «Switching remote URLs from HTTPS to SSH.»

Note: DSA keys (SSH-DSS) are no longer supported. Existing keys will continue to function, but you cannot add new DSA keys to your GitHub account.

Читайте также:  What is windows mobile operating system

Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.

Tip: If pbcopy isn’t working, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

In the upper-right corner of any page, click your profile photo, then click Settings.

In the user settings sidebar, click SSH and GPG keys.

Click New SSH key or Add SSH key.

In the «Title» field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key «Personal MacBook Air».

Paste your key into the «Key» field.

Click Add SSH key.

If prompted, confirm your GitHub password.

Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.

Tip: If clip isn’t working, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

In the upper-right corner of any page, click your profile photo, then click Settings.

In the user settings sidebar, click SSH and GPG keys.

Click New SSH key or Add SSH key.

In the «Title» field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key «Personal MacBook Air».

Paste your key into the «Key» field.

Click Add SSH key.

If prompted, confirm your GitHub password.

Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.

Tip: If xclip isn’t working, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

In the upper-right corner of any page, click your profile photo, then click Settings.

In the user settings sidebar, click SSH and GPG keys.

Click New SSH key or Add SSH key.

In the «Title» field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key «Personal MacBook Air».

bsara / git-ssh-auth-win-setup.md

Setup SSH Authentication for Git Bash on Windows

  1. Create a folder at the root of your user home folder (Example: C:/Users/uname/ ) called .ssh .
  2. 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

Читайте также:  Недостаточно системной памяти windows

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 $/.ssh create the config file with the following content:

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 :

Оцените статью