Find where a service loses access
Run as the service, namei stops exactly at the part it can't pass: the line with
Permission denied is the answer. Fix that part's permissions, not the file's — see
chmod-chown.
The namei command walks a path part by part and shows the type, mode and owner of each directory down to the file.
namei -l /etc/nginx/nginx.conf
type, mode, owner of each part
namei -m /var/www/html/index.html
modes only
namei -o /srv/app/data
owner and group only
namei /bin/sh
where symbolic links lead
namei -n /bin/sh
don't follow links
namei -x /home/student
mark mount points (D)
sudo -u www-data namei -l /srv/site/index.html
as the service
To open a file, a process passes through every directory of the path, and at each one
the kernel checks the x permission. ls -l shows the permissions of one part only.
namei walks the whole path and prints a line for each directory and for the file:
The first line is the path being resolved. Each following line has the type and mode
(d directory, - file, l link), the owner, the group and the part's name. How to
read the mode — permissions.
If it can't go further, namei prints the reason in place of the part it couldn't
reach:
The root directory gives others ---: without x you can't enter it, so .bashrc
can't be checked. namei doesn't judge permissions, it only shows them. Which triple
applies to an account you decide from the owner and group in the line.
-l is -m -o -v together; it's usually all you need. Full list — man namei.
| Option | What it does | Example |
|---|---|---|
-l --long |
Long format — type, mode, owner and group of each part of the path. | namei -l /etc/nginx/nginx.conf |
-m --modes |
Show the mode bits of each part. | namei -m /var/www/html/index.html |
-o --owners |
Show the owner and group of each part. | namei -o /srv/app/data |
-n --nosymlinks |
Don't follow symbolic links. | namei -n /bin/sh |
-x --mountpoints |
Mark mount point directories with a D. | namei -x /home/student |
-v --vertical |
Align modes and owners in columns. | namei -mov /srv/app |
Nothing found. Try a shorter query.
Run as the service, namei stops exactly at the part it can't pass: the line with
Permission denied is the answer. Fix that part's permissions, not the file's — see
chmod-chown.
Without -l, namei shows only types and expands each link with an indent: /bin/sh
is really /usr/bin/dash. More on links — links.
There's no part with that name. The lines above exist, so the typo or wrong letter case
is right here. Check the previous directory's contents: ls -la dir.
The directory on the line above has no x for whoever ran namei. Look at its triple
for your account (owner, group or others) and run namei as the right user with sudo
-u.
namei doesn't show ACLs, AppArmor, or the groups a process got when it started. Check
getfacl path (see acl); after usermod -aG a new login or a service restart is
needed — an old process keeps its old group list.
The file's own permissions are checked last. If any directory above is closed, the check
never reaches the file — find that directory with namei -l.
rwx and which triple applies.ls -ld dir.namei doesn't show.Found an inaccuracy? Report an error in the article