Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

The JVM will not start remote JMX because others can read the password file

Your error

Error: Password file read access must be restricted: /opt/app/jmx/jmxremote.password1 more line it can show

Fix it fast

Most common cause, 1 of 3

Group or other users can read the file on the host

Hand the file to the account that launches java and strip every group and other bit.

Fix
sudo chown appuser:appuser /opt/app/jmx/jmxremote.password
sudo chmod 600 /opt/app/jmx/jmxremote.password
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Error: Password file read access must be restricted means the JMX agent found group or other permission bits on jmxremote.password and stopped the JVM. The JDK accepts only a file its owner alone can read and write. Run chmod 600 as the account that starts java; in images and Kubernetes, set the mode when the file is copied or mounted.

  • Applies to JDK 17, 21 and 25 LTS (27 current), Linux and macOS, Docker Engine 28-29, Kubernetes Secret volumes
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List the file named in the message with its mode and owner, and note which user runs the java process. The mode string shows which cause below applies.

Run this first
ls -l /opt/app/jmx/jmxremote.password
ps -eo user,args | grep '[j]ava'

Then find the line you see in this list and open its fix:

  1. 1Group or other users can read the file on the hostls -l shows -rw-r--r-- or -rw-r----- for the password file
  2. 2The image copied the file with the mode it had on your machineThe same flags work on the host, but the container exits at start with the error
  3. 3A Kubernetes Secret mounts the file with the default mode 0644The pod starts crash-looping with the error right after the password file moved into a Secret volume

What does the error look like?

  • Error: Password file read access must be restricted: /opt/app/jmx/jmxremote.password
  • Password file read access must be restricted

Cause 1 of 3

Group or other users can read the file on the host

You seels -l shows -rw-r--r-- or -rw-r----- for the password file

Check

The agent prints Password file read access must be restricted when any read or write bit for group or others is set on the password file. The JDK's native check tests exactly those four bits, and Oracle's JMX guide tells you to leave read and write to the owner only, because the file stores passwords in clear text.

Check
stat -c '%a %U:%G %n' /opt/app/jmx/jmxremote.password   # GNU stat, Linux

Fix

Hand the file to the account that launches java and strip every group and other bit. That account must still be able to read it: a root-owned 600 file under a non-root JVM swaps this error for Password file not readable.

Fix
sudo chown appuser:appuser /opt/app/jmx/jmxremote.password
sudo chmod 600 /opt/app/jmx/jmxremote.password

Verify

Restart the JVM with the same flags. The error is gone and the port set in com.sun.management.jmxremote.port (9010 here) is listening.

Verify
ss -ltn | grep 9010

Confirmed by docs.oracle.com

Did this fix it?

Cause 2 of 3

The image copied the file with the mode it had on your machine

You seeThe same flags work on the host, but the container exits at start with the error

Check

Inside a container image the mode usually comes from COPY. Docker keeps the permissions a file has in a local build context, gives files from a Git URL context mode 644, and makes copied files owned by UID 0 unless --chown is given.

Check
docker run --rm --entrypoint ls my-app -l /opt/app/jmx/jmxremote.password

Fix

Set owner and mode in the COPY instruction, using the user the image runs java as.

Fix
COPY --chown=appuser:appuser --chmod=600 jmxremote.password /opt/app/jmx/jmxremote.password
USER appuser

Verify

The listing inside the new image shows -rw------- with appuser as owner, and the container stays up.

Verify
docker build -t my-app .
docker run --rm --entrypoint ls my-app -l /opt/app/jmx/jmxremote.password

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

A Kubernetes Secret mounts the file with the default mode 0644

You seeThe pod starts crash-looping with the error right after the password file moved into a Secret volume

Check

Kubernetes writes each Secret key as a file with mode 0644 when the volume names no mode. Those group and other read bits are exactly what the JMX agent refuses.

Check
kubectl logs my-pod --previous | grep -i "password file"
kubectl get pod my-pod -o jsonpath='{.spec.volumes[*].secret}'

Fix

Add defaultMode to the secret volume. YAML takes the octal form; a JSON manifest needs the decimal value 256 for 0400. The JVM user must still be allowed to read the file, or the agent reports Password file not readable instead.

Fix
# pod spec; the container mounts jmx-auth at /etc/jmx
volumes:
  - name: jmx-auth
    secret:
      secretName: jmx-auth
      defaultMode: 0400

Verify

The mounted file shows -r-------- and the pod reaches Running.

Verify
kubectl exec my-pod -- ls -lL /etc/jmx/jmxremote.password

Confirmed by kubernetes.io

Did this fix it?

How do I stop it coming back?

  • Keep jmxremote.password in a private directory of the service account, not in the shared JDK folder, as the Oracle guide advises for machines with several users.
  • Set the mode where the file is created (COPY --chmod, defaultMode, your provisioning script), so a redeploy cannot quietly reset it to 644.
  • Make the entrypoint or service unit check the file with stat before java starts and exit with a clear message when the mode is not 600 or 400.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro, TaxiDex.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.