coollabsio/coolify · error · Exception

SSH key file was not created: {$keyLocation}

Error message

SSH key file was not created: {$keyLocation}

What it means

Thrown by PrivateKey::storeInFileSystem() (app/Models/PrivateKey.php:234). The disk->put() call reported success, but a follow-up $disk->exists($filename) check cannot find the file. On the local driver this should be impossible unless something deleted the file between put and exists (another worker, antivirus, a misbehaving sync daemon like OneDrive/Dropbox-style tooling on the host path), or the disk root configuration changed between calls.

Source

Thrown at app/Models/PrivateKey.php:234

        if ($lockHandle === false) {
            throw new \Exception("Failed to open lock file for SSH key: {$lockFile}");
        }

        try {
            if (! flock($lockHandle, LOCK_EX)) {
                throw new \Exception("Failed to acquire lock for SSH key: {$keyLocation}");
            }

            // Attempt to store the private key
            $success = $disk->put($filename, $this->private_key);

            if (! $success) {
                throw new \Exception("Failed to write SSH key to filesystem. Check disk space and permissions for: {$keyLocation}");
            }

            // Verify the file was actually created and has content
            if (! $disk->exists($filename)) {
                throw new \Exception("SSH key file was not created: {$keyLocation}");
            }

            $storedContent = $disk->get($filename);
            if (empty($storedContent) || $storedContent !== $this->private_key) {
                $disk->delete($filename); // Clean up the bad file
                throw new \Exception("SSH key file content verification failed: {$keyLocation}");
            }

            // Ensure correct permissions for SSH (0600 required)
            if (file_exists($keyLocation) && ! chmod($keyLocation, 0600)) {
                Log::warning('Failed to set SSH key file permissions to 0600', [
                    'key_uuid' => $this->uuid,
                    'path' => $keyLocation,
                ]);
            }

            return $keyLocation;
        } finally {

View on GitHub (pinned to 70b9acc424)

Solutions

  1. Check for external processes touching /data/coolify/ssh on the host (auditd, lsof, cron) and exclude it from cleanup/sync tools.
  2. Ensure only one Coolify instance uses this data directory.
  3. Retry the key save once the external interference is removed.
Defensive patterns

Strategy: validation

Try / catch

try {
    $privateKey->storeInFileSystem();
} catch (\Exception $e) {
    if (str_contains($e->getMessage(), 'was not created')) {
        // something external removes files from /data/coolify/ssh — audit host processes, then retry
    }
    throw $e;
}

Prevention

When it happens

Trigger: Storing an SSH key while an external process removes files in /data/coolify/ssh (backup tooling misconfigured to 'clean' the dir, host-side sync software, security scanner), or concurrent key deletions for the same uuid.

Common situations: Host cron jobs that sweep 'stale' files from data volumes; dual Coolify instances pointed at the same /data/coolify; aggressive EDR on the host deleting private-key-looking files.

Related errors


AI-assisted analysis of coollabsio/coolify@70b9acc424 (2026-08-17). Data as JSON: /api/errors/fc72cc122e951350. Report an issue: GitHub.