Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm currently logged in as a normal user in OS X.

I'd like to start a terminal session and login as user foo.

Is this possible?

share|improve this question
1  
Have you tried using su - foo? –  kraftan Nov 4 '10 at 21:02
    
@kraftan, awesome! post this as an answer and I'll accept it. –  macek Nov 4 '10 at 21:05

2 Answers 2

up vote 8 down vote accepted

Have you tried using su - foo?

Update based on the comments:

The empty - tells su to make a full login. That means (from the man page),

The environment is discarded except for HOME, SHELL, PATH, TERM, and USER. HOME and SHELL are modified as above. USER is set to the target login. PATH is set to ``/bin:/usr/bin''. TERM is imported from your current environment. The invoked shell is the target login's, and su will change directory to the target login's home directory.

So, if you need any other environment variables, such as DISPLAY to open programs that use the window server, you have to omit the empty -.

share|improve this answer
    
The login works fine but I tried mate myfile and I'm getting a "failed to connect to WindowServer" error. This isn't a critical fix, but it would be great to get this working. –  macek Nov 4 '10 at 21:11
2  
@macek: That's because there's no Window Server (aqua) attached to the terminal. If the user is currently logged on in the graphic environment, try open -a TextMate myfile. –  Georg Schölly Nov 4 '10 at 21:13
1  
@macek: I'm not sure, but maybe su foo could do it. Omitting the - keeps the values environment variables. –  kraftan Nov 4 '10 at 21:15
    
Thank you for the help. @kraftan, perhaps update the answer to include both with a brief explanation. :) –  macek Nov 4 '10 at 21:26
    
@Georg, that didn't seem to work. –  macek Nov 4 '10 at 21:29

I have tried su many times but I found sudo to be easier. You can try

sudo -u <username>
share|improve this answer

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.