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.…