如何在 Windows 中修改 ~/.ssh 文件夹和文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23064052/
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-09 11:30:36  来源:igfitidea点击:

How to modify ~/.ssh folder & files in windows?

windowssshdirectoryhome-directory

提问by u353

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

我觉得我缺少一些关于 .ssh 目录如何在 Windows 中工作的基本概念。我在 OSX/Linux 中工作时没有遇到任何问题,就像我现在一样。我的最终目标只是将我现有的 ssh 密钥移动到默认的 ~/.ssh 目录中,并根据我的选择更新配置(您知道,正常的 ssh 密钥相关任务)。

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...):

但是,每当我尝试将现有的 SSH 密钥移动到 ~/.ssh 目录,或打开它,甚至创建配置文件时,我都会收到以下错误(在 gitbash、puttygen 等中...) :

Puttygen (saving the key to disk):

Puttygen(将密钥保存到磁盘):

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

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

或在 gitbash 中(尝试做任何事情,包括创建配置文件):

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

亲切的问候, u353

采纳答案by u353

This isn't supported as Windows doesn't recognize dot files as directories.

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

回答by Bryson

I have created and regularly use a ".ssh" directory on Windows 7; as mentioned in the above comments, Windows Explorer doesn't support them, or more specifically, the error-checking in Windows Explorer does not allow you to give a file name that starts with a period. That same restriction does not exist in the command prompt or powershell.

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

Also, as mentioned above, it appears you have a file called ".ssh" in your home directory, which must be removed before you can create a folder named ".ssh".

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

Once such a folder exists, you can open it and change/create files in it using Windows Explorer; it just won't let you name a folder/file ".ssh" directly.

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

Gitbash should directly allow you to run "rm .ssh" and "mkdir .ssh", at which point everything else should work.

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

回答by mega6382

It is quite possible to add a .in the beginning of a directories name using File Explorer, it can be easily done by adding a .at the end of the directory name as well. For example:

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

To create a directory named .shh, just add the name as .ssh.and it will be created without any error.

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

And as @Bryson mentioned, this can be done from the cli as well, without appending a .at the end.

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

回答by cody.codes

Coming to this in 2018, given that on Windows 10 you have the Optional Feature OpenSSH clientinstalled it appears that on Windows a .sshfolder is created for you under C:\Users\<your_username>\.ssh

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

This is a feature that allows you to use PowerShell to SSH into remote hosts, and seems to be pretty similar in usage to the Linux/Unix equivalent. It was already installed for me when I setup my computer, but you can read the following for how to verify it's installed or install it:

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

You can check if it's installed by going to Settings -> Manage Optional Features, and then checking if you see OpenSSH in the list. If it is then your .ssh folder is probably in your home directory C:\Users\<your_username>\.ssh. If you need to install it then click "Add a feature", locate OpenSSH Client, click it and click install to install it.

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

回答by dqthe

This answer for Windows environment:

Windows环境的这个答案:

At the beginning, Windows didn't have .sshfolder.

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

When your run command for creating a ssh key like this:

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

ssh-keygen -t rsa -b 4096 -C "[email protected]"(must run your terminal as administrator).

ssh-keygen -t rsa -b 4096 -C "[email protected]"必须以管理员身份运行您的终端)。

Your is_rsaand id_rsa.pubfiles will be placed under /c/Users/your_username/

您的is_rsaid_rsa.pub文件将被放置在/c/Users/your_username/

So, you need to create folder /c/Users/your_username/.sshyourself then copy the ssh files to there. You also have to create file /c/Users/your_username/.ssh/configand edit it for the first time.

因此,您需要/c/Users/your_username/.ssh自己创建文件夹,然后将 ssh 文件复制到那里。您还必须创建文件/c/Users/your_username/.ssh/config并进行第一次编辑。

Next ssh will be placed under the .sshfolder automatically.

接下来 ssh 将自动放置在该.ssh文件夹下。

Note: ~/is the same as /c/Users/your_username/on Windows

注意:~//c/Users/your_username/在 Windows 上相同