Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
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 '09 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 '09 at 17:04
up vote 6 down vote accepted


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".

share|improve this answer
Thank you for this suggestion. It did the trick ... – esc1729 Aug 4 '09 at 16:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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