[英]How to modify ~/.ssh folder & files in windows?
I feel like I am missing some fundamental concept as to how the .ssh directory works in windows.我觉得我缺少一些关于 .ssh 目录如何在 Windows 中工作的基本概念。 I have had no issues when working in OSX/Linux like I am having now.
我在 OSX/Linux 中工作时没有遇到任何问题,就像我现在一样。 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 密钥移动到默认的 ~/.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
This answer for Windows environment : Windows环境的这个答案:
At the beginning, Windows didn't have .ssh
folder.一开始,Windows 没有
.ssh
文件夹。
When your run command for creating a ssh key like this:当您的运行命令用于创建这样的 ssh 密钥时:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
( must run your terminal as administrator ). ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
(必须以管理员身份运行终端)。
Your is_rsa
and id_rsa.pub
files will be placed under C:\\Users\\your_username\\
您的
is_rsa
和id_rsa.pub
文件将放置在C:\\Users\\your_username\\
So, you need to create folder C:\\Users\\your_username\\.ssh
yourself then copy the ssh files to there.因此,您需要自己创建文件夹
C:\\Users\\your_username\\.ssh
然后将 ssh 文件复制到那里。 You also have to create file C:\\Users\\your_username.ssh\\config and edit it for the first time.您还必须创建文件C:\\Users\\your_username.ssh\\config并进行第一次编辑。
Next ssh will be placed under the .ssh
folder automatically.接下来 ssh 将自动放置在
.ssh
文件夹下。
Note: ~/
is the same as C:\\Users\\your_username\\
on Windows注意:
~/
与 Windows 上的C:\\Users\\your_username\\
相同
I have created and regularly use a ".ssh" directory on Windows 7;我在 Windows 7 上创建并定期使用“.ssh”目录; 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.
正如上面的评论中提到的,Windows 资源管理器不支持它们,或者更具体地说,Windows 资源管理器中的错误检查不允许您提供以句点开头的文件名。 That same restriction does not exist in the command prompt or powershell.
命令提示符或 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;一旦存在这样的文件夹,您就可以使用 Windows 资源管理器打开它并在其中更改/创建文件; it just won't let you name a folder/file ".ssh" directly.
它不会让您直接将文件夹/文件命名为“.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”,此时其他一切都应该可以工作。
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.
要创建名为
.shh
的目录,只需将名称添加为.ssh.
and it will be created without any error.它将被创建而不会出现任何错误。
And as @Bryson mentioned, this can be done from the cli as well, without appending a .
正如@Bryson 所提到的,这也可以从 cli 完成,而无需附加
.
at the end.在末尾。
Coming to this in 2018, given that on Windows 10 you have the Optional Feature OpenSSH client installed it appears that on Windows a .ssh
folder 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.这是一项允许您使用 PowerShell 通过 SSH 连接到远程主机的功能,并且在用法上似乎与 Linux/Unix 等效项非常相似。 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:
当我设置我的计算机时,它已经为我安装了,但是您可以阅读以下内容以了解如何验证它是否已安装或安装:
You can check if it's installed by going to Settings -> Manage Optional Features, and then checking if you see OpenSSH in the list.您可以通过转到设置 -> 管理可选功能来检查它是否已安装,然后检查是否在列表中看到 OpenSSH。 If it is then your .ssh folder is probably in your home directory
C:\\Users\\<your_username>\\.ssh
.如果是,那么您的 .ssh 文件夹可能位于您的主目录
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 客户端,单击它并单击安装以安装它。
Use git bash on windows go to home directory as在 Windows 上使用 git bash 转到主目录作为
$ cd
then to check .ssh folder on home directory use然后检查主目录上的 .ssh 文件夹使用
$ ls -A
you will be able to see a ./ssh folder there您将能够在那里看到一个 ./ssh 文件夹
$ cd ./ssh
$ ls
you will be able to see the config files if exists如果存在,您将能够看到配置文件
To transfer any key-pair or any files to this folder use below command First to that directory in which you already have key-pair要将任何密钥对或任何文件传输到此文件夹,请使用以下命令首先到您已经拥有密钥对的目录
$ cp name_of_key-pair_file.pem ~/.ssh/
为了解决这个问题,我使用了 git batsh 控制台
First of all, if you want to generate SSH files, all you need to do is run this command:首先,如果你想生成 SSH 文件,你需要做的就是运行这个命令:
ssh-keygen
Once you did, .ssh folder will be generated in this path:完成后,将在此路径中生成.ssh 文件夹:
C:\Users\your_username\
For checking what files are in .ssh folder you can easily run this command:要检查 .ssh 文件夹中的文件,您可以轻松运行以下命令:
ls ~/.ssh
with this above command, you can see all your ssh files which would be like this:使用上面的命令,您可以看到所有的 ssh 文件,如下所示:
id_rsa id-rsa.pub
Please note that:请注意:
id_rsa : It's a private file and id-rsa.pub : It's a public file id_rsa :这是一个私人文件和id-rsa.pub :这是一个公共文件
so, if you like to see inside of that file or whatever you like just type this command :因此,如果您想查看该文件的内部或任何您喜欢的内容,只需键入以下命令:
cat ~/.ssh/id_rsa.pub
这不受支持,因为 Windows 无法将点文件识别为目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.