{"record":{"id":"7598e4338b8ed81a","repo":"coollabsio/coolify","slug":"failed-to-create-ssh-keys-storage-directory","errorCode":null,"errorMessage":"Failed to create SSH keys storage directory","messagePattern":"Failed to create SSH keys storage directory","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/Models/PrivateKey.php","lineNumber":276,"sourceCode":"    public static function deleteFromStorage(self $privateKey)\n    {\n        $filename = \"ssh_key@{$privateKey->uuid}\";\n        $disk = Storage::disk('ssh-keys');\n\n        if ($disk->exists($filename)) {\n            $disk->delete($filename);\n        }\n    }\n\n    protected function ensureStorageDirectoryExists()\n    {\n        $disk = Storage::disk('ssh-keys');\n        $directoryPath = '';\n\n        if (! $disk->exists($directoryPath)) {\n            $success = $disk->makeDirectory($directoryPath);\n            if (! $success) {\n                throw new \\Exception('Failed to create SSH keys storage directory');\n            }\n        }\n\n        // Check if directory is writable by attempting a test file\n        $testFilename = '.test_write_'.uniqid();\n        $testSuccess = $disk->put($testFilename, 'test');\n\n        if (! $testSuccess) {\n            throw new \\Exception('SSH keys storage directory is not writable. Run on the host: sudo chown -R 9999 /data/coolify/ssh && sudo chmod -R 700 /data/coolify/ssh && docker restart coolify');\n        }\n\n        // Clean up test file\n        $disk->delete($testFilename);\n    }\n\n    public function getKeyLocation()\n    {\n        return Storage::disk('ssh-keys')->path(\"ssh_key@{$this->uuid}\");","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Models/PrivateKey.php#L258-L294","documentation":"Thrown by PrivateKey::ensureStorageDirectoryExists() (app/Models/PrivateKey.php:276), called at the top of storeInFileSystem(). If the 'ssh-keys' disk root does not exist, it attempts $disk->makeDirectory('') and treats a false return as a hard failure. In practice the storage root is the configured disk root (e.g. /data/coolify/ssh inside the container), and makeDirectory fails when the parent path is not writable by the Coolify process — so the directory cannot be (re)created.","triggerScenarios":"First key save after install when /data/coolify (the parent) is root-owned and /data/coolify/ssh does not yet exist; the ssh dir was deleted while the container was running; a misconfigured 'ssh-keys' disk root pointing somewhere unwritable.","commonSituations":"Fresh self-hosted installs with wrong volume ownership; operators deleting /data/coolify/ssh to 'reset'; custom filesystems.php config with a bad root path.","solutions":["On the host: sudo chown -R 9999 /data/coolify/ssh && sudo chmod -R 700 /data/coolify/ssh && docker restart coolify (create the dir first if the parent lacks it: sudo mkdir -p /data/coolify/ssh).","Verify the 'ssh-keys' disk root in config/filesystems.php points at the intended path.","Retry the key save; ensureStorageDirectoryExists() will pass once the root exists and is writable."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-flight: ensure the ssh-keys root exists and is creatable/writable\n$root = Storage::disk('ssh-keys')->path('');\nif (! is_dir($root) && ! @mkdir($root, 0700, true)) {\n    throw new \\RuntimeException(\"Cannot create SSH storage root: {$root}\");\n}\nif (! is_writable($root)) {\n    throw new \\RuntimeException(\"SSH storage root not writable: {$root}\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $privateKey->storeInFileSystem();\n} catch (\\Exception $e) {\n    if (str_contains($e->getMessage(), 'Failed to create SSH keys storage directory')) {\n        // create+chown the root on the host: mkdir -p /data/coolify/ssh && chown -R 9999 … && docker restart coolify\n    }\n    throw $e;\n}","preventionTips":["Bake correct ownership into install/restore procedures: /data/coolify must let uid 9999 create subdirectories.","Never delete /data/coolify/ssh out from under a running instance."],"tags":["coolify","ssh-key","file-storage","permissions","installation"],"backgroundTag":"file-write-permission-denied","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}