4

I came from Linux world , and not familiar with OS X admin. Now I want to su to another user , but it just not working ... Where goes wrong here ?

smallufo@miniserver:~ $ whoami
smallufo
smallufo@miniserver:~ $ su - postgres
Password:
smallufo@miniserver:~ $ whoami
smallufo
smallufo@miniserver:~ $

I input correct password , but why I cannot su to postgres ?

Sorry if it is a dumb question , but I've been stuck with it the whole night...

Thanks a lot !

smallufo
  • 199
  • 2
  • 8

2 Answers2

5

su should work normally in OS X. @Scott Warren's idea about the postgres user's shell is a possible explanation, but OS X doesn't use /etc/passwd except during bootup. Normal users (and groups etc) are stored in .plist files under /var/db/dslocal/nodes/Default/. The easy way to look at (and modify) them is with the dscl command:

dscl . -read /Users/postgres  # prints all user attributes
dscl . -read /Users/postgres UserShell # prints just the default shell

If necessary, you can set the shell the same way:

sudo dscl . -create /Users/postgres UserShell /bin/bash
Gordon Davisson
  • 11,216
  • 4
  • 28
  • 33
  • Thanks a lot , it works ! ... though I don't understand the design consideration of Mac OS X ... I'll bookmark this question. – smallufo Nov 02 '11 at 08:44
  • 1
    OS X doesn't use /etc/passwd because its format is too limited -- a fixed number of fields per user, and no ability to have large amounts of data in the fields. Compare with a user record in OS X, where you'll often (but not always) find a JPEGPhoto attribute (with a hex-encoded image), an MCXSettings attribute (with an often-huge XML description of the user's managed preference/parental controls settings), etc. You just can't do that in an /etc/passwd entry. – Gordon Davisson Nov 02 '11 at 14:20
  • Thanks Gordon. I think Apple should do something about `su` command as the user experience is very frustrating. – maksimov Jan 11 '13 at 13:54
2

I don't have Postgres installed but check your /etc/passwd file. The last entry for that user account will be the shell that user uses. In my passwd file the accounts that shouldn't login (_lp,_postfix,etc.) have a shell of /usr/bin/false but accounts that can login are usually /bin/sh.

Scott Keck-Warren
  • 1,670
  • 1
  • 14
  • 23
  • Hi , there is no 'postgres' user in /etc/passwd . But the user does exist. for example: I can see owner of '/usr/local/pgsql/data' is "postgres" . I don't know how Mac OSX (Snow Leopard) manage users. – smallufo Nov 01 '11 at 22:22