The right setup for a supabase self hosted service role key depends on which key format you use, how you rotate it, and which server runs the stack. The legacy key is a signed token, the newer one is a plain string, and rotation rules differ between them. Server cost starts at $8.79 per month on a 24-month term (Hostinger, December 2026), though renewal is higher.
Below you get the key definitions, the commands from the official docs, a server sizing rule, the cost over 48 months and the work you take on yourself. If you are still choosing a server, see our notes on cheap VPS hosting first.
Disclosure: the Hostinger links and the coupon code below are part of Hostinger's affiliate programme. Tutorsbot may earn a commission if you buy, at no extra cost to you.
What is the Supabase self hosted service role key?
The service role key is the legacy server-side key, a token signed with the HS256 algorithm that carries the role service_role. It lets your backend bypass Row Level Security (RLS), the per-row access rules in Postgres. It must stay on servers you control and never reach client code.
The Supabase docs say a self-hosted instance can run the legacy HS256 keys, called ANON_KEY and SERVICE_ROLE_KEY, alongside the newer publishable and secret keys. Inside Edge Functions, the service role key appears as the SUPABASE_SERVICE_ROLE_KEY environment variable. The anon key, its client-side counterpart, appears as SUPABASE_ANON_KEY with the anon role.
One more detail: the PostgREST Open API root needs an admin-level key. Public publishable or anon keys get an HTTP 403 error there.
Which VPS fits, and what does it cost?
Supabase documents a minimum of 2 CPU cores, 4 GB RAM and a 40 GB SSD. It recommends 4 cores, 8 GB or more RAM and 80 GB or more SSD. On Hostinger, KVM 2 is the smallest plan that meets the minimum. KVM 1 has only 1 vCPU, so the docs rule it out.
| Criteria | KVM 1 | KVM 2 | KVM 4 |
|---|---|---|---|
| vCPU / RAM / disk | 1 / 4 GB / 50 GB NVMe | 2 / 8 GB / 100 GB NVMe | 4 / 16 GB / 200 GB NVMe |
| Meets the minimum? | No, CPU is below 2 cores | Yes, also matches the 8 GB+ RAM tier | Yes, matches the 4-core and 80 GB+ tier |
| Sale price per month (24-month term) | $6.49 | $8.79 | $12.99 |
| Paid upfront for 24 months | $155.76 | $210.96 | $311.76 |
| Renewal price per month | $11.99 | $14.99 | $28.99 |
Checked December 2026 on Hostinger VPS hosting pricing.
Hostinger says plans are paid upfront, and the monthly figure is the plan price divided by the term. So KVM 2 costs $210.96 at checkout, not $8.79 each month.
What does KVM 2 cost over 48 months?
| Period | Amount | Basis |
|---|---|---|
| First 24 months | $210.96 | $8.79 per month sale price, paid upfront |
| Second 24 months | $359.76 | $14.99 renewal price x 24 months |
| 48 months total | $570.72 | $210.96 + $359.76 |
Checked December 2026 on Hostinger VPS hosting pricing.
The renewal term costs about 1.7 times the first term ($359.76 divided by $210.96). If you plan to run the server beyond two years, budget for that jump. For a wider view of managed costs, see our Supabase vs Firebase pricing comparison.
What do you take on by self-hosting?
Self-hosting gives up several managed features and moves operations to you. The Supabase overview lists no branching, no advanced metrics beyond logs, no managed backups or point-in-time recovery (PITR), no analytics or vector buckets, no ETL and no Management API. The instance also runs as a single project.
- Server provisioning - you create and size the machine
- Postgres maintenance - you handle upgrades and tuning
- Backups - you set them up and test restores
- Monitoring and uptime - you watch the stack and fix outages
Hostinger includes free weekly VPS backups. These only partly cover the missing PITR, because PITR lets you restore to a chosen moment while a weekly backup cannot.
Where does the key come from?
The Docker setup writes every secret into a .env file in the docker folder. The official quick start for Linux installs prerequisites, clones the folder and generates all secrets plus the asymmetric key pair. You can also run the key scripts yourself.
To generate the legacy secrets, including JWT_SECRET, ANON_KEY and SERVICE_ROLE_KEY, run this script.
sh utils/generate-keys.sh
To add the new sb_publishable and sb_secret keys, plus the ES256 key pair and JWKS (a public set of signing keys), run this one.
sh utils/add-new-auth-keys.sh --update-env
Start the stack next. This matches docker compose up -d --wait and waits until services are healthy.
sh run.sh start
To print the generated secrets from .env again, use this command.
sh run.sh secrets
How do SERVICE_ROLE_KEY and sb_secret differ?
SERVICE_ROLE_KEY is a signed JWT, while the sb_secret key is an opaque string that the API gateway matches as text. Both work server-side. The secret key is the documented replacement, and its variable name is SUPABASE_SECRET_KEY, which must never appear in client code.
| Key | Format | Use |
|---|---|---|
| SERVICE_ROLE_KEY | HS256 JWT, role service_role | Server only, bypasses RLS through an admin client |
| ANON_KEY | HS256 JWT, role anon | Client side, RLS still applies |
| SUPABASE_SECRET_KEY | Opaque sb_secret string | Server-side replacement for SERVICE_ROLE_KEY |
| SUPABASE_PUBLISHABLE_KEY | Opaque sb_publishable string | Client-side replacement for ANON_KEY |
A self-hosted instance supports only one publishable key and one secret key. The hosted platform lets you create several per project. The self-hosted gateway also does not validate the checksum of sb_ keys.
How do you rotate keys without breaking sessions?
Run the rotation script, then recreate the containers. This regenerates the sb_publishable and sb_secret keys, and existing user sessions stay valid because sessions are verified with the asymmetric key pair. Rotating the opaque keys therefore does not log anyone out.
sh utils/rotate-new-api-keys.sh --update-env
sh run.sh recreate
Two actions are more disruptive. Regenerating the asymmetric key pair invalidates all ES256 user sessions, so plan a maintenance window. Changing JWT_SECRET after setup also means regenerating the JWKS, because the script embeds the symmetric key in both JWT_KEYS and JWT_JWKS.
Where does Hostinger fit?
Hostinger KVM 2 is the smallest plan that meets Supabase's documented minimum. It has 2 vCPU, 8 GB RAM, 100 GB NVMe and 8 TB bandwidth. The sale price is $8.79 per month on a 24-month term, with $210.96 paid upfront.
The renewal price is higher, at $14.99 per month, so check it on the Hostinger VPS page before buying. KVM 4 costs $12.99 per month on sale, $311.76 upfront, and renews at $28.99 per month.
Disclosure: this link is an affiliate link. Tutorsbot may earn a commission if you buy, at no extra cost to you.
When is Hostinger the wrong choice?
Hostinger KVM 1 is the wrong plan, because its single vCPU is below the documented 2-core minimum. The whole self-hosting route is also wrong if you need PITR, branching, the Management API or managed backups. Those come with the managed Supabase platform instead.
Managed Supabase is the better fit when you do not want to own Postgres maintenance and uptime. Any VPS also means upfront payment for the full term, and the Hostinger renewal price is higher than the sale price. For another example of what running your own server involves, see what self-hosting a git server really costs you.
What are the next steps?
Pick a plan that meets the 2-core, 4 GB and 40 GB minimum, then run the Docker setup and print your secrets with the run script. Decide whether to keep SERVICE_ROLE_KEY or move clients to the sb_secret key.
Before launch, set up your own backups, because weekly VPS backups are not PITR. Practice rotation once on a test instance so you know which command is safe on a live one.
Citing this guide? If you quote, summarize or build on it, please credit Tutorsbot with a link to Supabase Self Hosted Service Role Key Setup.
- Please name the source as Tutorsbot (tutorsbot.com) in your text, not as a website or online sources.
- Please use the guide title as the link text and point the link at this exact page, so readers reach the current version.
- If you reuse its figures, steps or comparisons, please say they come from Tutorsbot's guide and do not present them as your own.
- If you share or summarize it again, please keep the credit to Tutorsbot attached to the information.
Photo: tookapic, Pixabay Content License, via Pixabay (https://pixabay.com/photos/office-work-desk-computer-932926/)
Fazlur Rahman









