Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在GCP中将ssh密钥添加到项目中_Ssh_Google Cloud Platform - Fatal编程技术网

如何在GCP中将ssh密钥添加到项目中

如何在GCP中将ssh密钥添加到项目中,ssh,google-cloud-platform,Ssh,Google Cloud Platform,我正在尝试将我的公共ssh密钥添加到我的项目中,但似乎无法使其正常工作。 根据文件:;创建ssh txt文件后,我需要使用以下命令: gcloud compute project-info add-metadata --metadata-from-file ssh-keys=[LIST_PATH] 我将ssh-txt文件命名为“ssh.txt”,文件的完整路径是:C:\Users\33768\Desktop\ssh.txt 我尝试了以下命令: gcloud compute project-in

我正在尝试将我的公共ssh密钥添加到我的项目中,但似乎无法使其正常工作。 根据文件:;创建ssh txt文件后,我需要使用以下命令:

gcloud compute project-info add-metadata --metadata-from-file ssh-keys=[LIST_PATH]
我将ssh-txt文件命名为“ssh.txt”,文件的完整路径是:C:\Users\33768\Desktop\ssh.txt

我尝试了以下命令:

gcloud compute project-info add-metadata --metadata-from-file ssh-keys=C:\Users\33768\Desktop\ssh.txt
gcloud compute project-info add-metadata --metadata-from-file ssh-keys="C:\Users\33768\Desktop\ssh.txt"
gcloud compute project-info add-metadata --metadata-from-file ssh-keys=C:/Users/33768/Desktop/ssh.txt
gcloud compute project-info add-metadata --metadata-from-file ssh-keys="C:/Users/33768/Desktop/ssh.txt"
然而,它们都不起作用,错误在于:

ERROR: (gcloud.compute.project-info.add-metadata) Unable to read file [LIST_PATH]: [Errno 2] No such file or directory: [LIST_PATH]
其中,我将命令行工具显示的实际列表路径替换为[list_path]。 请帮帮我,我快疯了。
Thx.

从你的帖子中我看到你在使用Windows。我不知道您是如何生成密钥的,所以我将从这个过程开始写下所有内容

下载Putty(它还包括PuttyGen)。运行PuttyGen,将“评论”字段更改为您的username@somemachine然后单击“生成”按钮。“鼠标移动”后,您将获得您的个人SSH密钥,该密钥如下所示:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAtJqgJA1MLB7ZqIL+xF0cnZaXyGW9LYxlyj/JrK/eOkgvRN36zI7xJc1ML5uO2Hn+EPiTwKO5+0xmwomZKnu2nrCsuZzQZakGWHiyKBYSQ1x+l+PqISOniiHOGTHc0p//lwbCLKO7bUUYuS2+7Uw3lNhKytnNA7WbcfMmm+NTH2C8ZdWptWaGmX/Yt1kdUKFCyTLAlXqdoNyr4QssdaMo4BY07JUrYHGN8Uzt7/Knd6zqqsK4Hzf0lTzxYdiuP3Y6qYBcAMtLs7iaEibu8r/i1Js7DpSHQTUYbQ6lWBk7p1yI8XJ809FTXLy20doF3ElQjBrqk/dkDk1p3AV2RlplYQ== username@somemachine
单击“保存公钥”并将其保存到某个目录中。然后“保存私钥”-理想情况下保存到同一目录

您已经生成并保存了密钥

现在-将它们添加到您的GCP项目中。最简单的方法是:

  • 控制台-转到计算引擎>元数据>-单击“编辑”按钮,然后单击“添加项”。将整个SSH密钥字符串复制到此框中,然后单击“保存”
  • gcloud SDK-
    gcloud compute project info add metadata--来自文件ssh key=your_file_name/name/和/path的元数据
    -添加时,您可能会收到警告
    以下密钥缺少前面的
    -别担心-它们仍然可以工作
如果有疑问,请阅读文档。虽然有点长,但一切都解释得很详细

此外,我在Linux上生成了密钥,并以同样的方式将它们添加到我的项目中,它也可以工作。

谢谢大家。 我真的找到了它不起作用的原因。我在windows上使用了ubuntu,这弄乱了我文件夹的路径。在ubuntu终端内部,我无法访问本地计算机上的文件夹,而这些文件夹不在我的ubuntu文件夹中。
在ubuntu终端外运行我的命令就行了

@John Hanley:[LIST_PATH],在本例中为ssh.txt,是要作为元数据上载的所有公钥(.pub)在单个文件中的串联。

元数据文件需要特定格式。ssh.txt的内容是什么?遮罩以隐藏实际关键点。