Menu

8 things I learned running ASP.NET Core as a systemd service on Ubuntu (no Docker)
📰

8 things I learned running ASP.NET Core as a systemd service on Ubuntu (no Docker)

DEV Community: dotnet·Dang Nguyen·3 days ago
#4LcC06JD
#devtodotnet#devto#dev#systemd#checklist
Long article (308 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: at the end of this post I link to a paid checklist I made ($9). Everything below is free to use without it. This post was drafted with AI assistance and reviewed by me.

I run a small ASP.NET Core app directly on an Ubuntu VPS with systemd and nginx, without containers. These are the points that cost me the most time:

MemoryDenyWriteExecute=true stops .NET from starting. The JIT needs memory that is writable and executable. Leave it off for .NET services.

Without SetApplicationName , every deploy signs users out. With a releases/<id> layout the content root changes each release, and Data Protection treats it as a new app. Fix the name:

builder . Services . AddDataProtection ( ) . SetApplicationName ( "example" ) . PersistKeysToFileSystem ( new DirectoryInfo ( "/var/lib/example/keys" ) ) ;

Enter fullscreen mode

Exit fullscreen mode

EnvironmentFile= is read by systemd (PID 1), not by your service user. Make it root:root 0600 ; the service needs no access to it.

Measure hardening.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.