在 Windows 上为 Bitbucket 设置 SSH 密钥

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36812519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:34:17  来源:igfitidea点击:

Setting up SSH keys for Bitbucket on Windows

windowsgitsshbitbucket

提问by Sujan Sundareswaran

First, I am an absolute noob with git, repos and command line. I have repo on Bitbucket and I basically want to be able to push to the repository via gitbash without entering a password each time.

首先,我是 git、repos 和命令行的绝对菜鸟。我在 Bitbucket 上有 repo,我基本上希望能够通过 gitbash 推送到存储库,而无需每次输入密码。

What I have:

我有什么

  • A repository on Bitbucket with the code already set up.
  • A local directory where the repository is cloned.
  • A public key and a private key generated via PuTTY.
  • Public key added to Bitbucket via the Manage SSH keys page.
  • Bitbucket 上已设置代码的存储库。
  • 克隆存储库的本地目录。
  • 通过 PuTTY 生成的公钥和私钥。
  • 通过管理 SSH 密钥页面添加到 Bitbucket 的公钥。

How do I now make it work so that I don't have to enter the password each time I push from the gitbash terminal? I'm using Windows 10.

我现在如何使其工作,以便每次从 gitbash 终端推送时都不必输入密码?我正在使用 Windows 10。

回答by Rajesh Kumar

Please follow the steps to add ssh key into bitbucket account to solve your issue.

请按照步骤将 ssh 密钥添加到 bitbucket 帐户以解决您的问题。

  1. Open git bash terminal and enter the command ssh-keygen -t rsa -C "your email address"
  2. Enter passphrase (leave it blank) and enter
  3. Enter the same phrase again (leave it blank) and enter
  4. Copy the id_rsa.pubfile content from where it is residing in your system (C:\Users\username\.ssh)
  5. Login to bitbucket account and click top right most user icon ->bitbucket settings->ssh keys under security menu then paste into key field and save it. 6.Restart your git bash terminal and enter git initcommand and add ssh git repository location [email protected]:username/repository_name.gitwhich is present in your bitbucket repository.
  1. 打开 git bash 终端并输入命令ssh-keygen -t rsa -C “您的电子邮件地址”
  2. 输入密码(留空)并输入
  3. 再次输入相同的短语(留空)并输入
  4. 从系统中的位置复制id_rsa.pub文件内容(C:\Users\username\.ssh
  5. 登录到 bitbucket 帐户并单击最右上方的用户图标 -> bitbucket 设置 -> 安全菜单下的 ssh 密钥,然后粘贴到密钥字段并保存。6.重启你的 git bash 终端并输入git init命令并添加 ssh git 存储库位置[email protected]:username/repository_name.git它存在于你的 bitbucket 存储库中。

Enjoy!

享受!

回答by Andrew

There are two ways to load a remote git repository: using SSH and using HTTPS.

有两种方法可以加载远程 git 存储库:使用 SSH 和使用 HTTPS。

SSH will use a key pair, and requires the public key to be added to your BitBucket/GitHub profile.

SSH 将使用密钥对,并要求将公钥添加到您的 BitBucket/GitHub 配置文件中。

HTTPS requires your BitBucket/GitHub username and password. You will be promoted for your password every time you interact with the remote server (clone, fetch, push, pull).

HTTPS 需要您的 BitBucket/GitHub 用户名和密码。每次与远程服务器交互(克隆、获取、推送、拉取)时,您都会被提升密码。

If you are currently being prompted for a password, that means the remote URL is currently set to use HTTPS. You can determine this be running git remote -v. To change to use SSH, you need to update the remote URL to the SSH URL by running git remote set-url <remote alias> <SSH URL>. If you only have one remote server, <remote alias>will be origin. You can find the SSH URL in BitBucket/GitHub under the clone option of the repository.

如果当前提示您输入密码,则表示远程 URL 当前设置为使用 HTTPS。您可以确定这正在运行git remote -v。要更改为使用 SSH,您需要通过运行将远程 URL 更新为 SSH URL git remote set-url <remote alias> <SSH URL>。如果您只有一台远程服务器,<remote alias>origin. 您可以在 BitBucket/GitHub 中存储库的克隆选项下找到 SSH URL。

回答by vagovszkym

1) create .ssh folder under your home directory like: mkdir C:\Users\USERNAME\.ssh

1)在您的主目录下创建 .ssh 文件夹,例如: mkdir C:\Users\USERNAME\.ssh

2) Copy id_rsa and id_rsa.pub into directory from previous step

2) 将 id_rsa 和 id_rsa.pub 复制到上一步的目录中

3) Close and open cmd (console window)

3)关闭并打开cmd(控制台窗口)

4) You need to clone the repository as SSH repository, like: git clone ssh://[email protected]:USERNAME/repository.git

4) 您需要将存储库克隆为 SSH 存储库,例如: git clone ssh://[email protected]:USERNAME/repository.git

Then it should work.

那么它应该工作。

回答by Alex

Following this guide

遵循本指南

I think you are missing that after you have generated the SSH keypair, you need to add the SSH private key to pageant, PuTTY's key management tool.

我认为您缺少在生成 SSH 密钥对后,您需要将 SSH 私钥添加到 PuTTY 的密钥管理工具 pageant。

First, run pageant, which can be found in the directory where you have installed PuTTY package (remember, by default: c:\Program Files\PuTTY). You will see a small icon in your system tray (see the screenshot to the right), which indicates pageant is started. Click on the icon and in pageant window click “Add Keys”. Add the private key that was generated by puttygen in the previous step. The private key has extension .ppk, that is the easiest way to distinguish it from the public key you have created.

首先,运行 pageant,它可以在您安装 PuTTY 包的目录中找到(请记住,默认情况下:c:\Program Files\PuTTY)。您将在系统托盘中看到一个小图标(请参见右侧的屏幕截图),表示选美活动已开始。单击图标,然后在选美窗口中单击“添加密钥”。添加上一步中 puttygen 生成的私钥。私钥的扩展名为 .ppk,这是区分它与您创建的公钥的最简单方法。

After you add the SSH key, you should see it in pageant key list.

添加 SSH 密钥后,您应该会在选美密钥列表中看到它。

回答by counterterror

Don't use PuTTY to generate the key. Create a new key with ssh-keygen in .ssh. Leave passwords blank. Open that new key in PuTTY. Copy and paste it into the Bitbucket Key field. Save key with PuTTY and Bitbucket. It should work.

不要使用 PuTTY 生成密钥。在 .ssh 中使用 ssh-keygen 创建一个新密钥。将密码留空。在 PuTTY 中打开那个新密钥。将其复制并粘贴到 Bitbucket Key 字段中。使用 PuTTY 和 Bitbucket 保存密钥。它应该工作。

回答by gsamaras

For Windows 7 users:

对于 Windows 7 用户:

  1. Open Git Bash and type ssh-keygen, and press Enter three times (one for location, and two for empty passphrase).
  2. Now, a dir .sshshould list these two files: id_rsa id_rsa.pub
  3. Add the public key to your Bitbucket settings, as described in Set up an SSH key , Step 3. You basically copy paste the contents of file "id_rsa.pub" to your profile in BitBucket via the web interface (no admin rights required of course).
  4. Restart Git Bash.
  5. Go the destination directory, where you would like to clone your repository and do a git init
  6. Get the ssh from the Clone of the repo, and then do git clone ssh://[email protected]:YOURUSERNAME/myrepository.git
  1. 打开 Git Bash 并输入ssh-keygen,然后按 Enter 三次(一次是位置,两次是空密码)。
  2. 现在,dir .ssh应该列出这两个文件: id_rsa id_rsa.pub
  3. 将公钥添加到您的 Bitbucket 设置中,如设置 SSH 密钥 ,第 3 步中所述。您基本上通过 Web 界面将文件“id_rsa.pub”的内容复制粘贴到您在 BitBucket 中的配置文件(当然不需要管理员权限) )。
  4. 重新启动 Git Bash。
  5. 转到目标目录,您要在其中克隆存储库并执行 git init
  6. 从 repo 的克隆中获取 ssh,然后执行 git clone ssh://[email protected]:YOURUSERNAME/myrepository.git

回答by Jamin

if you need to update multiple putty sessions on windows via powershell:

如果您需要通过 powershell 在 windows 上更新多个 putty 会话:

set-Itemproperty -path HKCU:\Software\SimonTatham\PuTTY\Sessions\sessionname -name PublicKeyFile -value "C:\Users\username.ssh\putty.ppk"

set-Itemproperty -path HKCU:\Software\SimonTatham\PuTTY\Sessions\sessionname -name PublicKeyFile -value "C:\Users\username.ssh\putty.ppk"