Windows 上的 SourceTree:如何连接到 SSH?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17790375/
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
SourceTree on Windows: How to connect to SSH?
提问by Community
I have an SSH access to my web hosting, it works great with PuTTY (I just had to enter my domain, username and password), however it seems much more complicated with SourceTree.
我可以通过 SSH 访问我的虚拟主机,它与 PuTTY 配合得很好(我只需要输入我的域、用户名和密码),但是使用 SourceTree 似乎要复杂得多。
While PuTTY has a field for "Host Name", "username" and "password", SourceTree doesn't and requires a special file ".ppk
"?!
虽然 PuTTY 有一个字段用于“主机名”、“用户名”和“密码”,但 SourceTree 没有并且需要一个特殊的文件.ppk
“?!
I need to connect SourceTree to my web hosting via SSH for the obvious reason that I want to use it to push to a remote repository located on my web hosting.
我需要通过 SSH 将 SourceTree 连接到我的虚拟主机,原因很明显,我想用它来推送到位于我的虚拟主机上的远程存储库。
So how do I get a .ppk
file generated from my domain/username/password?Any help greatly appreciated!
那么如何获取.ppk
从我的域/用户名/密码生成的文件?非常感谢任何帮助!
PS: I've noticed that they made it exceptionally easy to connect to BitBucket by offering two simple fields: "username" and "password", and made it exceptionally difficult to connect to a third-party SSH... Is it an intentional attempt to prevent competition?!
PS:我注意到他们通过提供两个简单的字段“用户名”和“密码”使连接到 BitBucket 变得异常容易,并且使连接到第三方 SSH 变得异常困难......这是故意的吗?企图阻止竞争?!
采纳答案by Community
There are two ways to connect SourceTree to any SSH.
有两种方法可以将 SourceTree 连接到任何 SSH。
1: The Simplest Way
1:最简单的方法
The simplest way is by using your domain name, username and password provided by your Web Hosting Provider:
最简单的方法是使用您的虚拟主机提供商提供的域名、用户名和密码:
Simply use the following syntax: ssh://[email protected]/
– SourceTree will then prompt you to enter your password whenever you push to that SSH:
只需使用以下语法:ssh://[email protected]/
– 无论何时推送到该 SSH,SourceTree 都会提示您输入密码:
If you check the Remember password
checkbox, your password will be saved and you will not be prompted again for it. You can edit or remove the stored password at a later time by going to Tools > Options > Authentication
as shown on the image below:
如果您选中该Remember password
复选框,您的密码将被保存,并且不会再次提示您输入密码。您可以在以后编辑或删除存储的密码,Tools > Options > Authentication
如下图所示:
Note: In my case (1&1 Shared Hosting), the username and password were both the same as my main FTP account.
注意:就我而言(1&1 共享主机),用户名和密码都与我的主 FTP 帐户相同。
2: The More Complex Way
2:更复杂的方式
The more complex way is by using a Private/Public Keys Pair:
更复杂的方法是使用私钥/公钥对:
This implies generating two keys (one "private" and one "public") using the "PuTTY Key Generator" (in SourceTree go to Tools > Create or Import SSH Keys
).
这意味着使用“ PuTTY 密钥生成器”(在 SourceTree 中转到Tools > Create or Import SSH Keys
)生成两个密钥(一个“私有”和一个“公共” )。
Once generated, save the private key to a .ppk
file and load it in SourceTree (Tools > Create or Import SSH Keys > Load
). It's not over yet: now you must add the public key to your server. To do that, add it to the following file on your web server: /.ssh/authorized_keys
.
生成后,将私钥保存到.ppk
文件中并将其加载到 SourceTree ( Tools > Create or Import SSH Keys > Load
) 中。它还没有结束:现在您必须将公钥添加到您的服务器。为此,请将其添加到 Web 服务器上的以下文件中:/.ssh/authorized_keys
.
If this file doesn't exist, save your public key to a file named authorized_keys
and upload it to your server via FTP. You must upload it into a directory named /.ssh/
located at the root (if it doesn't exist, simply create it).
如果此文件不存在,请将您的公钥保存到一个名为的文件中authorized_keys
,然后通过 FTP 将其上传到您的服务器。您必须将其上传到/.ssh/
位于根目录下的目录中(如果它不存在,只需创建它)。
Note: Make sure to use the mainFTP account of your hosting account. If it doesn't work, adjust the permissions (chmod) of the authorized_keys
file and set it to 777
using your FTP software (Right-click on "authorized_keys" > File permissions
):
注意:确保使用您的主机帐户的主FTP 帐户。如果它不起作用,请调整文件的权限 (chmod)authorized_keys
并将其设置为777
使用您的 FTP 软件 ( Right-click on "authorized_keys" > File permissions
):
No need for command line whatsoever.
不需要任何命令行。
回答by Anssssss
I had to do some additional work from Patoshi's answer.
我不得不从Patoshi 的回答中做一些额外的工作。
In Tools > Options > General > SSH Client Configuration, I had to point it to the id_rsa key, and select OpenSSH as the SSH Client (Putty/PLink is selected by default).
在工具 > 选项 > 常规 > SSH 客户端配置中,我必须将其指向 id_rsa 密钥,并选择 OpenSSH 作为 SSH 客户端(默认选择 Putty/PLink)。
Then each time you start SourceTree, a prompt will appear asking for the passphrase to decrypt the id_rsa key (assuming you created it with a passphrase to encrypt it). This looks like so:
然后每次启动 SourceTree 时,都会出现一个提示,要求输入密码来解密 id_rsa 密钥(假设您使用密码创建它来加密它)。这看起来像这样:
At that point, I could go to the Clone page, paste in the SSH address from my Gitlab project ([email protected]:Blah/Whatever.git) and it cloned it. No extra prompts for username or password (since it is using SSH keys).
那时,我可以转到克隆页面,粘贴来自我的 Gitlab 项目 ([email protected]:Blah/Whatever.git) 的 SSH 地址并克隆它。没有额外的用户名或密码提示(因为它使用 SSH 密钥)。
回答by Patoshi パトシ
I had some trouble getting SourceTree working with an existing git repo that resided on gitlab. I also had to figure out why it wasn't connecting as I was using puttygen to generate the keys.
我在让 SourceTree 使用驻留在 gitlab 上的现有 git 存储库时遇到了一些麻烦。我还必须弄清楚为什么它没有连接,因为我使用 puttygen 生成密钥。
Make sure after you generate your keys to export it to the OpenSSH format
确保在生成密钥后将其导出为 OpenSSH 格式
You place this file in your c:\user\MYUSERNAME.ssh folder as the file:
您将此文件作为文件放在 c:\user\MYUSERNAME.ssh 文件夹中:
- id_rsa
- id_rsa.pub
- id_rsa
- id_rsa.pub
the id_rsa is the private key file and .pub is the public key file that you paste into your other application, which in my case was gitlab.
id_rsa 是私钥文件,.pub 是您粘贴到其他应用程序中的公钥文件,在我的例子中是 gitlab。