Executing a command as a nologin user
Solution 1:
One way is to launch a shell for that user (explicitly specifying the shell):
sudo -u www-data bash
This will launch a (bash) shell as the specified user. You can then execute your command(s) and logout (to return to your previous shell)
Solution 2:
As root you can use su -s /bin/sh $user
— the -s
option overrides the configured shell for the user.