Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Erich

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
add comment

1 Answer

up vote 5 down vote accepted

Try:

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
add comment

Your Answer

 
discard

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.