WARNING: UNPROTECTED PRIVATE KEY FILE! when trying to SSH into Amazon EC2 Instance

前端 未结 11 2222
慢半拍i
慢半拍i 2020-12-12 11:06

I\'m working to set up Panda on an Amazon EC2 instance. I set up my account and tools last night and had no problem using SSH to interact with my own personal instance, but

11条回答
  •  情深已故
    2020-12-12 11:43

    The solution is to make it readable only by the owner of the file, i.e. the last two digits of the octal mode representation should be zero (e.g. mode 0400).

    OpenSSH checks this in authfile.c, in a function named 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;
    }
    

    See the first line after the comment: it does a "bitwise and" against the mode of the file, selecting all bits in the last two octal digits (since 07 is octal for 0b111, where each bit stands for r/w/x, respectively).

提交回复
热议问题