Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.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
Amazon web services 密码保护pem文件_Amazon Web Services_Encryption_Amazon Ec2_Pem_Ssh Keygen - Fatal编程技术网

Amazon web services 密码保护pem文件

Amazon web services 密码保护pem文件,amazon-web-services,encryption,amazon-ec2,pem,ssh-keygen,Amazon Web Services,Encryption,Amazon Ec2,Pem,Ssh Keygen,我想使用受密码保护的pem文件SSH到我的EC2实例中。如何对pem文件进行密码保护?我以前做过,但不记得是怎么做的。我获取了AWS生成的pem文件,并对其运行了一些命令,它生成了如下内容: -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: AES-128-CBC,<BlahBlahBlah> <encrypted stuff is here> -----END RSA PRIVATE K

我想使用受密码保护的pem文件SSH到我的EC2实例中。如何对pem文件进行密码保护?我以前做过,但不记得是怎么做的。我获取了AWS生成的pem文件,并对其运行了一些命令,它生成了如下内容:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,<BlahBlahBlah>

<encrypted stuff is here>

-----END RSA PRIVATE KEY-----
sudo chmod 755 KEY_PAIR_PRIVATE.key

但是生成的加密文件(具有我正在查找的正确头)似乎不起作用。当我尝试使用加密的pem文件进行ssh时,我得到了“权限被拒绝(公钥)。”。我能够用SSH将未加密的pem文件放入这个盒子中

这是因为您使用的命令会生成一个新的密钥对,而不是保护您现有的私钥

Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
尝试使用
ssh-keygen的
-p
选项

ssh-keygen -p -f my_private_key
它将提示您输入密码短语并保护您的私钥

Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
现在,如果您在
ssh
中使用
my\u private\u key
,它将提示输入密码短语,并将成功

 -p      Requests changing the passphrase of a private key file instead of
         creating a new private key.  The program will prompt for the file
         containing the private key, for the old passphrase, and twice for
         the new passphrase.

您可以安装和使用puttygen:

sudo apt install putty
要生成受保护的密钥,请执行以下操作:

puttygen KEY_PAIR_PRIVATE.pem -O private-openssh -o KEY_PAIR_PRIVATE.key -P
选项-p是将新密码短语设置为私钥

Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
提示:您可能需要设置使用密钥的权限,如下所示:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,<BlahBlahBlah>

<encrypted stuff is here>

-----END RSA PRIVATE KEY-----
sudo chmod 755 KEY_PAIR_PRIVATE.key
最后,您可以安全地访问aws实例:

ssh -i KEY_PAIR_PRIVATE.key ubuntu@IP_EC2_INSTANCE_OR_HOSTNAME

太棒了,成功了!谢谢你知道为什么一个地区的pem文件在另一个地区不起作用吗?我四处打听了一下,似乎应该行得通。我甚至选择了“使用已经存在的pem文件”,并且必须选中“是”复选框,表示我有pem文件。除非您在所有区域中上载了相同的对应公钥,否则私钥不会在区域之间共享。尽管区域给了我选择私钥的选项,但不会在区域之间共享?也许我遗漏了一些需要上传公钥的细节。当他们让我选择时,我想我不需要这样做it@LampShade是什么让你可以选择它?您在AWS控制台中吗?密钥对是区域性的。如果您在us-west-1中启动,并在AWS控制台中使用EC2启动向导,那么您将只看到与us-west-1相关的密钥对。其他地区也是如此。如果有机会,我会给你发一个屏幕截图,在设置EC2实例的最后,它会要求创建一个新的pem文件或选择一个已经存在的文件。即使在另一个地区,它也让我可以选择一个已经存在的地区(我在另一个地区创建的地区)。但后来它不起作用了。。。这很奇怪。