brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: su -s /bin/bash www-data tests permissions as a user that has no login shell

Permissions
~/tips/tip-permissions-su-shell-for-nologin-user

sudo su -s /bin/bash www-data

Opens a shell as a service account to try file access step by step.

Service accounts like www-data have /usr/sbin/nologin as their shell, so a plain su www-data just says the account is not available. With -s you choose the shell yourself.

As root, start a bash shell as that account:

sudo su -s /bin/bash www-data
id
ls -l /srv/site/uploads
touch /srv/site/uploads/test && rm /srv/site/uploads/test

Now you can walk the path the web server walks and see exactly where it hits Permission denied. I find that faster than testing one file at a time when a whole folder tree is involved, since you can cd around and try reads and writes.

For a single command you don’t need a shell at all:

sudo su -s /bin/sh -c 'cat /srv/site/config.php > /dev/null' www-data

This doesn’t change the account. The nologin shell stays in /etc/passwd, so nobody can log in as www-data over SSH. Only root can do this, because su as root doesn’t need the target’s password.

Remember to exit when done. Files you create in that shell belong to www-data, which is the point of testing, but don’t leave them behind. And the real service can still differ: systemd sandboxing, AppArmor and extra groups set in a unit file all apply to the service, not to your shell.

Further reading: su(1) manual page

More Permissions tips sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data newgrp media sudo journalctl -k --since '10 min ago' | grep 'apparmor="DENIED"' All Permissions tips (30) All topics

Link