23

I have to check if my web page running locally on nginx does not work due to permission issue. My web scripts are running as _www user, so I tried to switch to _www but this does not work:

maciek@macus:~$ sudo su - _www
Password:
maciek@macus:~$ whoami
maciek

How can I do this in 10.8.5?

2 Answers 2

18

The sudo is failing because the _www user has /usr/bin/false as its shell, causing the session to end as soon as you've switched user.

The solution is to use the -s option, which will execute your current shell instead of _www's shell:

$ sudo -s -u _www
Password:
$ whoami
_www

Just tested on a 10.9 system but it should work fine on 10.8.

2
  • normal users should not use sudo. Jan 5, 2016 at 11:38
  • 2
    @CousinCocaine define normal? are we normal?
    – Ray Foss
    Sep 20, 2017 at 17:28
23

Use login:

$ login
login: username
Password:
Last login: Day Month Date HH:MM:SS on ttys000
$ whoami
username

4
  • 1
    I don't think that system users have passwords. It prompts for password, and empty does not work.
    – Maciej Sz
    Apr 2, 2014 at 19:13
  • 3
    this is the correct way to do it. Jan 5, 2016 at 11:37
  • As the OP commented, this won't work for users that don't have passwords (which the _www user won't have by default, nor should it have one).
    – mjturner
    Jan 5, 2016 at 13:53
  • This solved an issue I was having when using nano after using su - username to switch users in Terminal. The window would get garbled when changing window size while in nano. Thank you for this-- I've been looking for a solution for days.
    – John
    Apr 1, 2020 at 6:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .