← Chmod Calculator
Your token

Chmod Calculator API

Reading a mode, explaining it, the risk check and the chmod, find and chown commands all run free in the browser and need no API. The API is for the one metered step: send a description of who needs what access, or a Permission denied error with the ls -l output, and get back a mode, owner and commands for each path.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

Send "task" first. This app has one job:

taskWhat it doesReply
adviseReads the situation (and any error, ls -l or stat output in it) and recommends the narrowest mode, owner or group for each path the visitor named, with single permission commands in the order to run them, ending with a check. It never recommends 777, everyone-write or setuid.{"task":"advise","summary","diagnosis","changes":[{"path","kind","mode","owner","group","why"}],"commands":[{"cmd","why"}],"warnings":[...],"questions":[...]}

Input fields

FieldTypeMeaning
taskstring"advise". Required.
situationstringYour own words plus anything you paste: the error, ls -l, namei -l, id. The page sends at most 6,000 characters, keeping the start and the end. Required.
factsstringJSON text: current (the mode open in the calculator: mode, ls, kind, name, or null), listing (every ls -l or stat line found in the situation, with its octal mode), errors (permission error lines), cut_characters. Required; send {"current":null,"listing":[],"errors":[],"cut_characters":0} if you have none.

The reply

job.output.output is JSON text in the shape above. The page keeps a change only when its path is one the visitor wrote (or a name inside a folder they wrote), its mode is octal or rwx letters, and it does not let everyone write; it keeps a command only when it is a single permission command (chmod, chown, chgrp, setfacl, usermod, gpasswd, find -exec chmod, or a check such as ls, stat, namei, id) with no chaining or redirection. It flags a chmod number that differs from the matching change. If the balance ran low, truncated is true and the object may stop early; the parts that arrived whole are kept.

Worked examples

task: advise - a PHP upload folder the web server cannot write

Input (input.json):

{
  "task": "advise",
  "situation": "My PHP site can't save uploaded photos. PHP-FPM runs as www-data. I deploy the code with git as the user deploy.\n\nWarning: move_uploaded_file(/var/www/shop/uploads/cat.jpg): Failed to open stream: Permission denied in /var/www/shop/upload.php on line 14\n\n$ ls -ld /var/www/shop /var/www/shop/uploads\ndrwxr-xr-x 6 deploy deploy 4096 Mar  3 10:12 /var/www/shop\ndrwxr-xr-x 2 deploy deploy 4096 Mar  3 10:12 /var/www/shop/uploads",
  "facts": "{\"current\":{\"mode\":\"755\",\"ls\":\"drwxr-xr-x\",\"kind\":\"folder\",\"name\":\"/var/www/shop/uploads\"},\"listing\":[{\"name\":\"/var/www/shop\",\"ls\":\"drwxr-xr-x\",\"mode\":\"755\",\"owner\":\"deploy\",\"group\":\"deploy\",\"kind\":\"folder\"},{\"name\":\"/var/www/shop/uploads\",\"ls\":\"drwxr-xr-x\",\"mode\":\"755\",\"owner\":\"deploy\",\"group\":\"deploy\",\"kind\":\"folder\"}],\"errors\":[\"Warning: move_uploaded_file(/var/www/shop/uploads/cat.jpg): Failed to open stream: Permission denied in /var/www/shop/upload.php on line 14\"],\"cut_characters\":0}"
}

Reply:

{
  "task": "advise",
  "summary": "Give the uploads folder to the www-data group and let that group write there, with setgid so new files keep the group.",
  "diagnosis": "PHP-FPM runs as www-data, but /var/www/shop/uploads is owned by deploy:deploy with mode 755, so www-data falls in the last class, which cannot write. The parent /var/www/shop is 755, so www-data can already reach the folder.",
  "changes": [
    {
      "path": "/var/www/shop/uploads",
      "kind": "folder",
      "mode": "2775",
      "owner": "",
      "group": "www-data",
      "why": "www-data writes here through its group, deploy keeps ownership, and setgid keeps new files in the www-data group."
    }
  ],
  "commands": [
    {
      "cmd": "sudo chgrp www-data /var/www/shop/uploads",
      "why": "Give the folder to the group PHP-FPM runs as."
    },
    {
      "cmd": "sudo chmod 2775 /var/www/shop/uploads",
      "why": "Group can add and remove files; new files keep the group; others cannot write."
    },
    {
      "cmd": "ls -ld /var/www/shop/uploads",
      "why": "Check that the group is www-data and the mode is drwxrwsr-x."
    }
  ],
  "warnings": [
    "Only the uploads folder is changed; the rest of /var/www/shop stays owned by deploy and read-only for www-data.",
    "Files already in uploads keep their old owner and group, so check them if PHP must replace them."
  ],
  "questions": [
    "Is www-data really the account PHP-FPM runs as on this server, as you wrote?"
  ]
}

task: advise - an SSH key that is too open

Input:

{
  "task": "advise",
  "situation": "$ ssh -i ~/.ssh/id_ed25519 sam@build.example.org\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\nPermissions 0644 for '/home/sam/.ssh/id_ed25519' are too open.\nIt is required that your private key files are NOT accessible by others.\nThis private key will be ignored.\n\n$ ls -la ~/.ssh\ntotal 24\ndrwxrwxr-x  2 sam sam 4096 Mar  3 10:12 .\ndrwxr-x--- 18 sam sam 4096 Mar  3 10:10 ..\n-rw-rw-r--  1 sam sam  402 Mar  1 09:00 authorized_keys\n-rw-r--r--  1 sam sam  411 Mar  1 09:00 id_ed25519\n-rw-r--r--  1 sam sam  102 Mar  1 09:00 id_ed25519.pub\n-rw-r--r--  1 sam sam  888 Mar  2 11:30 known_hosts",
  "facts": "{\"current\":{\"mode\":\"644\",\"ls\":\"-rw-r--r--\",\"kind\":\"file\",\"name\":\"id_ed25519\"},\"listing\":[{\"name\":\".\",\"ls\":\"drwxrwxr-x\",\"mode\":\"775\",\"owner\":\"sam\",\"group\":\"sam\",\"kind\":\"folder\"},{\"name\":\"..\",\"ls\":\"drwxr-x---\",\"mode\":\"750\",\"owner\":\"sam\",\"group\":\"sam\",\"kind\":\"folder\"},{\"name\":\"authorized_keys\",\"ls\":\"-rw-rw-r--\",\"mode\":\"664\",\"owner\":\"sam\",\"group\":\"sam\",\"kind\":\"file\"},{\"name\":\"id_ed25519\",\"ls\":\"-rw-r--r--\",\"mode\":\"644\",\"owner\":\"sam\",\"group\":\"sam\",\"kind\":\"file\"},{\"name\":\"id_ed25519.pub\",\"ls\":\"-rw-r--r--\",\"mode\":\"644\",\"owner\":\"sam\",\"group\":\"sam\",\"kind\":\"file\"},{\"name\":\"known_hosts\",\"ls\":\"-rw-r--r--\",\"mode\":\"644\",\"owner\":\"sam\",\"group\":\"sam\",\"kind\":\"file\"}],\"errors\":[\"@ WARNING: UNPROTECTED PRIVATE KEY FILE! @\",\"Permissions 0644 for '/home/sam/.ssh/id_ed25519' are too open.\"],\"cut_characters\":0}"
}

Reply:

{
  "task": "advise",
  "summary": "Set the private key to 600, and tighten the .ssh folder to 700 and authorized_keys to 600 so SSH accepts them.",
  "diagnosis": "SSH ignores ~/.ssh/id_ed25519 because its mode is 644, so other users can read it. The .ssh folder (775) and authorized_keys (664) are also writable by the group, which SSH dislikes.",
  "changes": [
    {
      "path": "~/.ssh/id_ed25519",
      "kind": "file",
      "mode": "600",
      "owner": "",
      "group": "",
      "why": "SSH only accepts a private key that nobody but the owner can read."
    },
    {
      "path": "~/.ssh",
      "kind": "folder",
      "mode": "700",
      "owner": "",
      "group": "",
      "why": "SSH wants the folder holding keys to be private to its owner."
    },
    {
      "path": "~/.ssh/authorized_keys",
      "kind": "file",
      "mode": "600",
      "owner": "",
      "group": "",
      "why": "Group write on authorized_keys can make the SSH server refuse it."
    }
  ],
  "commands": [
    {
      "cmd": "chmod 600 ~/.ssh/id_ed25519",
      "why": "Make the private key readable and writable by you only."
    },
    {
      "cmd": "chmod 700 ~/.ssh",
      "why": "Close the folder to the group and everyone else."
    },
    {
      "cmd": "chmod 600 ~/.ssh/authorized_keys",
      "why": "Remove group write from authorized_keys."
    },
    {
      "cmd": "ls -la ~/.ssh",
      "why": "Check the new modes."
    }
  ],
  "warnings": [
    "Leave id_ed25519.pub and known_hosts at 644; they hold no secrets and SSH accepts them."
  ],
  "questions": []
}

On the page, every mode in the answer is worked out again, checked, and can be opened in the calculator.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://chmod-calculator.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"chmod-calculator"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "advise", "situation": "nginx gets Permission denied on /srv/app/static ...", "facts": "{...}"}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="chmod-calculator:advise:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: task, summary, diagnosis, changes, commands, warnings, questions
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: chmod-calculator:advise:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json