Short answer: the same four defaults keys that lock any Mac Dock, plus one more that matters far more here than anywhere else: turn off recent apps, because on a walk-up machine that section shows the previous person what they were working on.
If the Mac restores to an image on reboot, set the locks before the image is captured, or the restore will take them off every night.
A classroom Mac has thirty people who can be told not to do something. A library or walk-up Mac has none of that, and it changes what you are actually defending against.
Public machines usually run a single account that is logged in permanently and never signs out. That makes the ordinary defaults route more durable here than in a classroom with per-student logins, because there is only one account for the settings to live in.
defaults write com.apple.dock size-immutable -bool true
defaults write com.apple.dock position-immutable -bool true
defaults write com.apple.dock contents-immutable -bool true
defaults write com.apple.dock autohide-immutable -bool true
killall Dock
Each one grays out the matching control in System Settings, so it cannot be changed from the interface at all. They survive a restart, a sleep and a macOS update. The full list with every key’s type is in every Mac Dock defaults command.
macOS adds a section of recently used applications to the right of the Dock. On your own Mac it is a convenience. On a walk-up Mac it is a list of what the previous person opened, shown to the next person who sits down.
defaults write com.apple.dock show-recents -bool false
killall Dock
The four locks above do not remove it, because it is a separate setting. Turn it off deliberately. More on it in how to stop recent apps appearing in the Dock.
Many public Macs are set to return to a known state, either through imaging software or by restoring a disk snapshot on reboot. That is the right way to run a machine like this, and it has one consequence people meet the hard way:
Anything you configure after the baseline was captured is undone the next time the machine restores. Your Dock locks are configuration. Set them, confirm them, and only then capture the image. If the Mac is already in service, the change belongs in the baseline, not in the running session, or you will be setting it again every morning and wondering why.
The same applies to the recent apps setting and to the Dock’s actual contents. Arrange the Dock exactly as the public should find it, then capture.
Worth being precise, because the three mechanisms are not interchangeable.
defaults command is undone by another defaults command. Anyone who can open Terminal can lift all four in a minute.For a public machine with no Terminal access in the hands of the public, the ordinary locks are usually enough. For one where Terminal is reachable, they are not.
No. It stops the Dock changing. Restricting which apps can run is a separate matter, and Screen Time or your management tool is where that belongs. The two are fine together and solve different problems.
Only if the reboot happens often enough. A machine that restores nightly still spends a full day drifting, and the drift is worst in the afternoon when the most people have used it.
Yes. They live in the account’s preferences rather than in the system, so an update leaves them alone. A restore image, on the other hand, will replace them with whatever the baseline holds.
Preferences are stored per account, so anything set in one login does not appear in another. Set the locks in the account the public actually uses. If that account is one macOS clears between sessions, the settings will go with it, and the answer is a device-scoped profile from a management tool rather than a command.
The commands are identical. The situations are not: a classroom has accounts, supervision and someone to tell, and a front desk has a second screen a customer can see. See locking the Dock on a classroom Mac, on a front desk or showroom Mac, on a family Mac, or the shared Mac guide for the general case.