12
# su -l www-data ./http-app.py
This account is currently not available.
# su -l www-data -c ./http-app.py
This account is currently not available.
# su -c ./http-app.py www-data 
This account is currently not available.
# su -lc ./http-app.py www-data 
This account is currently not available.
# getent passwd www-data 
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
# getent shadow www-data 
www-data:*:16842:0:99999:7:::
# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.6 (jessie)
Release:        8.6
Codename:       jessie

What's wrong with my su or www-data? It used to work...

Presumably this is because of the /usr/sbin/nologin, but how then I drop root for this one script, without compromising other services on the system (nologin has been chosen by Debian team for a good reason, I want to believe)?

15

Without debating su vs. sudo you can try adding -s /bin/sh to your command line. (I could not verify this option is available for jessie since the Debian manpages webserver isn't working: https://manpages.debian.org/)

  • I've incorrectly assumed that /bin/sh is used by default and you must specify -s option only if you wanna change to /bin/bash or similar. – NarūnasK Dec 2 '16 at 10:32
  • 3
    Thanks, it works in Debian 9 su www-data -s /bin/sh to get back to root just type su. – PJ Brunet Sep 22 '17 at 3:42
  • 3
    @PJBrunet - "to get back to root" (assuming you su'd from root) you would type "exit". To start a new root shell you would type su. – ChronoFish Jan 25 '18 at 14:19
17

You are using su which is used to "switch user". Of course it won't work because www-data is a user account which cannot be used to login. You have told it: /usr/sbin/nologin.

Maybe what you want is sudo which is used to "execute a command as another user".

sudo -u www-data ./http-app.py
  • I always used su for this purpose and it always used to work. sudo is an extra package to install, but you are right, I can use it to achieve what I want. – NarūnasK Dec 1 '16 at 22:38
0

If you want not only execute one command, but switch to www-data in order to test some stuff for that user, this worked for me:

sudo -u www-data sh

It's a little bit shorter. Exit the session with [ctrl]+[d] or exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.