I’m managing a CentOS 4.7 server with several for security reasons shell-less user accounts. But sometimes I need a user-shell for installations anyway. What is the best way to get a login shell? Just now I use

sudo –u <user> bash –rcfile /home/<user>/.bash_profile

But this is not perfect. A lot of the environment variables are not intitialized.


  • A very quick suggestion: you might want to be specific about the environment variables you're finding aren't set to your liking.
    – esm
    Aug 4, 2009 at 14:23
  • Especially HISTFILE and HOME were not set which annoyed me most. Anyway, esm provided the command I was looking for.
    – esc1729
    Aug 4, 2009 at 17:04

1 Answer 1



sudo -u <user> -H -- bash -l

The sudo argument "-H" will set the home directory properly, and the "-l" option to bash will indicate that this is a login shell. You might also experiment with adding the bash argument "-p".


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.