StrictModes constraints on authorized_keys file permissions
0 reputation · 16 Aug 2023, 16:45 UTC
0 reputation · 16 Aug 2023, 16:45 UTC
OpenSSH utilizes the StrictModes configuration to ensure that authentication keys are stored in a secure environment. When enabled, the SSH daemon validates that the authorized_keys file and its parent directory are not writable by group or others.
A design uncertainty arises when balancing security requirements with automated deployment tools that may inadvertently modify file ownership or permissions during configuration updates. If permissions are set too loosely, the server ignores the key file, resulting in a silent authentication failure on the client side.
StrictModes violation for the .ssh directory versus the authorized_keys file?31775 reputation · 16 Aug 2023, 19:32 UTC
When StrictModes yes is set, sshd will refuse to use an authorized_keys file if any of the following conditions are true:
~/.ssh directory is writable by the group or others (i.e., its mode has any of the bits 022 set).~/.ssh/authorized_keys file is writable by the group or others (mode & 022 != 0).In practice this means the directory should be mode 700 (or at least 755 without group/other write) and the file mode 600 (or 644 without group/other write). Any additional write permission for group or other triggers a StrictModes violation.
The daemon does not walk the entire path above the home directory; it checks only three objects: the user's home directory (the one that contains .ssh), the .ssh directory itself, and the authorized_keys file. If the home directory is group‑writable, sshd will also reject the key, but it does not inspect parent directories such as /home or the root.
ls -ld ~ ~/.ssh ~/.ssh/authorized_keysdrwxrwxr-x or -rw-rw-r--), correct them:chmod 700 ~/.sshchmod 600 ~/.ssh/authorized_keyschown $USER:$USER ~/.ssh ~/.ssh/authorized_keysIf after fixing the permissions you still see authentication failures, please provide the output of the ls -ld command above so we can confirm whether any higher‑level directory is unintentionally group‑writable.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 17 Aug 2023, 03:05 UTC
Automated deployment tools frequently modify $HOME ownership or apply recursive permission changes, which can silently trigger StrictModes rejection even when .ssh and authorized_keys retain correct modes. Verification requires checking not only ls -ld ~/.ssh authorized_keys but also ls -ld ~ for group or other write bits. If $HOME mode includes group/write for any non-owner account, sshd will ignore the key file regardless of deeper directory permissions.