How to change Minecraft server difficulty
Difficulty controls mob damage, hunger and whether hostile mobs spawn at all. Changing it is one line, and the reason it sometimes does not stick catches almost everybody once.
The four settings
Peaceful removes hostile mobs entirely and refills hunger over time. Easy, normal and hard scale mob damage and hunger effects upward, and only on hard can starvation kill you outright rather than leaving you on half a heart.
Hard also lets zombies break down wooden doors and spawn reinforcements, which matters more for a survival base than the raw damage numbers do.
Peaceful is worth knowing about for build servers, since it removes the need for lighting entirely.
In server.properties
Stop the server, open server.properties, and set:
difficulty=normalOlder versions used numbers, where 0 was peaceful and 3 was hard. Modern versions take the word. Save, then start the server.
Edit the file while the server is stopped. A running server rewrites it on shutdown and will overwrite your change, which is the single most common reason a difficulty edit appears to do nothing. The server.properties reference lists the rest of the file.
With a command, while running
/difficulty hardTakes effect immediately, no restart. This writes to the world rather than to the properties file, which is where the confusion starts.
Why it keeps reverting
There is a lock. If level.dat has DifficultyLocked set, the world ignores both the properties file and the command, and the difficulty you set never applies. That flag is set automatically when a world is created in hardcore mode.
The other cause is the ordering above: you edited the file while the server was running, and the shutdown wrote the old value back over it. Stop first, edit second, start third.
On a multiworld server, difficulty is per world. Setting it globally in the properties file only affects the default world, and each additional world carries its own value.
Hardcore is a separate switch
hardcore=true forces hard difficulty, locks it, and turns death into a ban or spectator mode depending on version. It is not a fifth difficulty level, it is a mode that pins the difficulty and changes what death means.
Turning hardcore off later leaves the difficulty lock in place, so you will need to clear that flag before the setting responds again. If you are running a server around this, our hardcore server list shows how other people handle the death rule, which varies far more than the difficulty does.