20

I feel like I am missing some fundamental concept as to how the .ssh directory works in windows. I have had no issues when working in OSX/Linux like I am having now. My end goal is simply to move my existing ssh key into the default ~/.ssh directory, and update the config if I so choose (you know, normal ssh key related tasks).

However, any time I have tried to move my existing SSH key over to the ~/.ssh directory, or open it, or even create a config file I just get the following error (in either gitbash, puttygen, etc...):

Puttygen (saving the key to disk):

Overwrite existing file C:\Users\me\.ssh?

or in gitbash (attempting to do anything, including just create the config file):

touch: creating `/c/Users/me/.ssh/config': No such file or directory

cd ~/.ssh

sh.exe": cd: /c/Users/me/.ssh: Not a directory

What am I missing/not understanding?

Kind Regards, u353

4

8 回答 8

22

Windows环境的这个答案:

一开始,Windows 没有.ssh文件夹。

当您创建这样的 ssh 密钥的运行命令时:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"必须以管理员身份运行您的终端)。

您的is_rsaid_rsa.pub文件将被放置在C:\Users\your_username\

因此,您需要C:\Users\your_username\.ssh自己创建文件夹,然后将 ssh 文件复制到那里。您还必须创建文件C:\Users\your_username.ssh\config并首次对其进行编辑。

接下来ssh会自动放到.ssh文件夹下。

注意:与Windows~/相同C:\Users\your_username\

于 2019-10-09T03:44:50.547 回答
8

我在 Windows 7 上创建并经常使用“.ssh”目录;正如上面评论中提到的,Windows Explorer 不支持它们,或者更具体地说,Windows Explorer 中的错误检查不允许您提供以句点开头的文件名。命令提示符或 powershell 中不存在相同的限制。

此外,如上所述,您的主目录中似乎有一个名为“.ssh”的文件,必须先删除该文件,然后才能创建名为“.ssh”的文件夹。

一旦存在这样的文件夹,您就可以使用 Windows 资源管理器打开它并在其中更改/创建文件;它只是不允许您直接命名文件夹/文件“.ssh”。

Gitbash 应该直接允许您运行“rm .ssh”和“mkdir .ssh”,此时其他一切都应该工作。

于 2015-11-10T07:58:35.950 回答
4

鉴于在 Windows 10 上安装了可选功能OpenSSH 客户端,在 2018 年实现这一点,看来在 Windows 上.ssh为您创建了一个文件夹C:\Users\<your_username>\.ssh

这是一个允许您使用 PowerShell 以 SSH 连接到远程主机的功能,并且在使用上似乎与 Linux/Unix 等价物非常相似。当我设置我的计算机时,它已经为我安装了,但您可以阅读以下内容以了解如何验证它是否已安装或安装:

您可以通过转到“设置”->“管理可选功能”来检查它是否已安装,然后检查是否在列表中看到 OpenSSH。如果是,那么您的 .ssh 文件夹可能在您的主目录C:\Users\<your_username>\.ssh中。如果您需要安装它然后单击“添加功能”,找到 OpenSSH 客户端,单击它并单击安装进行安装。

于 2018-11-28T16:15:04.927 回答
4

使用文件资源管理器在目录名称的开头添加 a 是很可能的.,也可以通过.在目录名称的末尾添加 a 来轻松完成。例如:

要创建一个名为 的目录.shh,只需添加名称 as .ssh.,它将被创建而不会出现任何错误。

正如@Bryson 提到的,这也可以从 cli 中完成,而无需.在末尾附加 a 。

于 2018-10-17T13:59:34.423 回答
1

在 Windows 上使用 git bash 转到主目录

$ cd

然后检查主目录使用的 .ssh 文件夹

$ ls -A 

您将能够在那里看到一个 ./ssh 文件夹

$ cd ./ssh
$ ls

如果存在,您将能够看到配置文件

要将任何密钥对或任何文件传输到此文件夹,请使用以下命令首先到您已经拥有密钥对的目录

$ cp name_of_key-pair_file.pem ~/.ssh/
于 2020-06-28T05:56:02.397 回答
0

为了解决这个问题,我使用了 git batsh 控制台

于 2021-05-11T23:06:55.480 回答
-1

首先,如果你想生成 SSH 文件,你需要做的就是运行这个命令:

ssh-keygen

完成后,将在此路径中生成.ssh 文件夹:

C:\Users\your_username\

要检查 .ssh 文件夹中的文件,您可以轻松运行以下命令:

ls ~/.ssh

使用上面的命令,您可以看到所有 ssh 文件,如下所示:

id_rsa   id-rsa.pub

请注意:

id_rsa:这是一个私人文件和 id-rsa.pub:这是一个公共文件

因此,如果您想查看该文件的内部或任何您喜欢的内容,只需输入以下命令:

cat ~/.ssh/id_rsa.pub
于 2021-11-09T16:41:21.280 回答
-23

这不受支持,因为 Windows 不将点文件识别为目录。

于 2014-04-16T17:03:01.513 回答