Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'd like to switch to another user without logging out the first user, then log in as a third user without logging out the other two, and so on, then switch between all users quickly. I'd like to insert passwords only once for each user obviously.

Is there an analogous way to do this like with processes, where I can send them to the background and foreground with ctrl-z and fg as needed?

share|improve this question
add comment

2 Answers

Use su <user>, optionally with the - option (also known as -l or --login) to make the shell behave as a login shell (different initialization).

You can't really send it to background, since the shell of that user catches the SIGTSTP signal that is used to move it to background and exits (usually). Instead of that you might be interested in a terminal multiplexer like tmux or screen

You might also want to use vlock on the consoles when you are not using them for longer time.

share|improve this answer
    
I figured that su alone would not be an option, but thanks for mentioning the exact reason. After skimming the wikipedia article on screen, I always wondered why I would need it ("useful for dealing with multiple programs from a command line"), as I can handle multiple programs with ctrl-z and fg already, but if it's the only way to switch between users quickly without re-entering passwords like I would have to with su, then that would be a killer feature. But is this really the only way? Is there a maximum of one user that can be logged in on a "normal" terminal (without a multiplexer)? –  bug Apr 5 '13 at 8:20
1  
Well, there is a maximum of one foreground process group on a tty (roughly the process group that gets the input). If you managed to get the su backgrounded without the shell terminating, it would work. As for other usage for terminal multiplexer, once you have more than 10 shells open, you realize that a terminal multiplexer is the way to go. :) –  peterph Apr 5 '13 at 8:45
2  
You can't suspend with Ctrl-Z, but you can suspend with the suspend builtin (or kill -s STOP "$$" if your shell doesn't have such a builtin). –  Stephane Chazelas Apr 5 '13 at 9:45
add comment
up vote 0 down vote accepted

Stephane Chazelas wrote:

You can't suspend with Ctrl-Z, but you can suspend with the suspend builtin (or kill -s STOP "$$" if your shell doesn't have such a builtin).

Thank you very much, this appears to work like a charm. After I'm logged in as another user, suspend sends the shell to the background and returns control to the previous user's shell. Then I can use fg as I would with any other job to resume. As far as I've tried, it even seems to work with more than two users and in ssh (which suspends with ~^z cause it's a login shell). No need to use a terminal multiplexer like screen after all.

PS: Unfortunately I can't find documentation on how to quote, so I just used block-quotes and mentioned the original author of the accepted answer.

share|improve this answer
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.