我正在亚马逊EC2实例上设置Panda。 我昨晚设置了我的帐户和工具,使用SSH与我自己的个人实例交互没有问题,但现在我不被允许进入Panda的EC2实例。 从熊猫开始

我得到以下错误:

@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @

Permissions 0644 for '~/.ec2/id_rsa-gsg-keypair' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.

昨晚,为了进入我的个人实例,我已经将我的keypair chmod为600,并尝试将权限设置为0,甚至生成新的密钥字符串,但似乎什么都不起作用。

任何帮助都是极大的帮助!


嗯,似乎除非目录的权限设置为777,否则ec2-run-instances脚本无法找到我的密钥文件。


当前回答

解决方案是使它仅由文件的所有者可读,即八进制模式表示的最后两位数字应该为零(例如模式0400)。

OpenSSH在authfile.c中,在一个名为sshkey_perm_ok的函数中检查:

/*
 * if a key owned by the user is accessed, then we check the
 * permissions of the file. if the key owned by a different user,
 * then we don't care.
 */
if ((st.st_uid == getuid()) && (st.st_mode & 077) != 0) {
    error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
    error("@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @");
    error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
    error("Permissions 0%3.3o for '%s' are too open.",
        (u_int)st.st_mode & 0777, filename);
    error("It is required that your private key files are NOT accessible by others.");
    error("This private key will be ignored.");
    return SSH_ERR_KEY_BAD_PERMISSIONS;
}

请参阅注释后的第一行:它对文件的模式执行“按位和”操作,选择最后两个八进制数字中的所有位(因为07是0b111的八进制数字,其中每个位分别代表r/w/x)。

其他回答

在windows上,尝试使用git bash并使用您的Linux命令。容易的方法

chmod 400 *****.pem

ssh -i "******.pem" ubuntu@ec2-11-111-111-111.us-east-2.compute.amazonaws.com

私钥文件需要保护。在我的情况下,我一直在使用public_key身份验证很长一段时间,我过去设置权限为600 (rw- --- ---)私钥和644 (rw- r——r——)和主文件夹中的.ssh文件夹,你将有700权限(rwx --- ---)。要设置此设置,请转到用户的主文件夹并运行以下命令

为“。ssh”文件夹设置700权限

chmod 700 .ssh

设置私钥文件权限为600

chmod 600 .ssh/id_rsa

设置公钥文件权限为644

chmod 644 .ssh/id_rsa.pub
sudo chmod 700 ~/.ssh 
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub

以上3个命令应该可以解决这个问题!

使用chmod命令修改文件权限

sudo chmod 700 keyfile.pem

请确保包含私钥文件的目录设置为700

chmod 700 ~/.ec2