71

While logged in as root I would like to su to a specific regular user. I run su username and immediately receive the prompt back, still as root. There is no error given. I'm aware of the old "the user you're trying to su to doesn't have permission for the folder you're currently in" problem, and that's not the case in this scenario. Furthermore, there is no error displayed, which is always the case (as far as I know) when that particular permissions issue is encountered.

I've tried su - username with the same effect. The command is processed, no errors are seen, and I receive the prompt back immediately.

What could be causing this behavior? How can I troubleshoot this?

3
  • 8
    What shell does the user have? Is it /bin/false?
    – camh
    May 25, 2012 at 5:47
  • 7
    You should really be using sudo -u username -s (or -i) BTW.
    – mgorven
    May 25, 2012 at 6:57
  • 2
    @camh facepalm That was it. I swear I checked /etc/passwd last night and it wasn't like that! =) Can you put that as an answer? I'll accept it.
    – Wesley
    May 25, 2012 at 17:05

6 Answers 6

99

Check what shell the user has in /etc/passwd. If the shell is /bin/false (a common shell to disallow logins), then you will see the behavior you describe. Alternatively, it may be some other immediately-terminating program that gives the same effective result.

3
  • 2
    That was it. I swear I looked first! =)
    – Wesley
    May 26, 2012 at 2:42
  • 37
    And if you need to debug something under user which has /bin/falseas its shell, you can do it with su - user -s /bin/sh.
    – Marki555
    May 27, 2012 at 8:47
  • /bin/false replaced to /bin/bash in password file solved the problem Mar 14, 2022 at 17:34
9

I'd suggest using strace on the su process to see where the process is failing.

strace su donaldduck

Should give you LOTS of output to sort through, but something in there should indicate where the problem is occurring.

2
  • With strace -s 2048 donald The size of strings is increased and you can read a PAM message from last read call.
    – Loenix
    Nov 14, 2021 at 15:15
  • Uh, thank you, but in case you weren't aware that question was asked and answered 10 years ago.
    – Magellan
    May 18, 2022 at 1:48
5

You should check the shell in /etc/passwd, and, without wishing to be patronising, check the output of whoami after running su.

1
  • 1
    Not sure why that would be considered patronizing, for I certainly wouldn't have taken it that way. I mean I can if you want, but that wouldn't be my first inclination. =) Anyway, yes, I forgot to state that I did that just to make sure I was who I thought I was, and I was still root and not the user I was trying to switch to.
    – Wesley
    May 25, 2012 at 16:59
2

For login as a root user

$ ssh root@localhost

Enter the root password

$ vi /etc/passwd

Replace the line in file

username:x:100:100:User:/home/user:/sbin/nologin

to

username:x:100:100:User:/home/user:/bin/bash

Log off and log in. It will show the user again

2
  • (1) The question says that the OP is already logged in as root — why complicate things by adding ssh?  (2) The OP is a root user, so he probably understands that you typically need to enter a password in order to login; you don’t need to spell that out.  (2b) And please don’t say “admin password” when you mean “root password”.  Some systems have an “admin” account that’s separate from the “root” account, so it’s confusing if you use the names interchangeably.  (3) If you’re going to show a shell prompt for root, it should be # .  … (Cont’d) May 22, 2022 at 17:26
  • (Cont’d) … (4) The heart of your answer is that the target user might have a pseudo-shell entry in /etc/passwd that prevents the account from being usable.  This answer has been presented already (arguably, twice).  (5) Logging out and in again should not be necessary.  (6) Your statement “It will show the user again” is peculiar — the user was never hidden. May 22, 2022 at 17:26
1

Another issue: I had exit command in

/home/user/.bashrc
0

Check your system logs : using sudo should log all the actions. So if there is a problem, it should be written.

You must log in to answer this question.

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