Not able to do "su -" . getting error "su: user - does not exist " !

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (All Versions)

Issue

  • Not able to do "su -" . getting error "su: user - does not exist " !
[testsys] /home/alpha> su -
su: user - does not exist
  • If execute 'su' the able to login as 'root'

Resolution

  • Remove alias, or use "su".
  • Alias is defined in .bashrc file of user home directory.
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias su='su -'                      ------------------here
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

Root Cause

  • An alias was in place that replaced "su" with "su -". The effective command being run was "su - -", causing the syntax error.

Diagnostic Steps

  • Running an strace displayed the root user logging in correctly. Aliases would not be in effect during the strace.

  • su always considers the last (or singular) argument presented to it is the intended login name, except for when issuing a "su -" by itsself:

  if (optind < argc && STREQ (argv[optind], "-"))
    {
      simulate_login = true;
      ++optind;
    }
  if (optind < argc)
    new_user = argv[optind++];          <--- optind being one less than argc, optind++ will be the last arg 

  pw = getpwnam (new_user);
  if (! (pw && pw->pw_name && pw->pw_name[0] && pw->pw_dir && pw->pw_dir[0]
     && pw->pw_passwd))                                                      <-- full check for valid user
    error (EXIT_FAIL, 0, _("user %s does not exist"), new_user);          
  • Only issuing an incorrect "su options -" would cause the program to try to look up "-" as a user. An alias must be in place.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments