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?

Wesley
  • 13,963
  • 12
  • 35
  • 49

6 Answers6

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.

camh
  • 38,261
  • 8
  • 74
  • 62
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.

Mat
  • 51,578
  • 10
  • 158
  • 140
Magellan
  • 576
  • 3
  • 10
  • 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 '21 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 '22 at 01:48
5

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

Jander
  • 16,272
  • 6
  • 50
  • 66
Alex Chamberlain
  • 2,050
  • 3
  • 17
  • 26
  • 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 '12 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

Cherry
  • 51
  • 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) – G-Man Says 'Reinstate Monica' May 22 '22 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.* – G-Man Says 'Reinstate Monica' May 22 '22 at 17:26
1

Another issue: I had exit command in

/home/user/.bashrc
Dek4nice
  • 33
  • 4
0

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

Dom
  • 918
  • 5
  • 13