3

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?

3 Answers 3

7

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.

3
  • 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, 2013 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, 2013 at 8:45
  • 3
    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). Apr 5, 2013 at 9:45
1

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.

0

One possible way would be to use a program like screen or tmux

Create a new screen named foo

screen -S foo   

Create another screen

ctrl+ a + c

Switch between them

ctrl+ a + a

alternatively press the number of the shell to jump to it

ctrl+ a + 1

You can view the name / number of all open screen sessions like so:

ctrl+ a + w

These will be 3 separate shells, but they will all be inside 1 terminal.

1
  • peterph already mentioned screen and tmux. This answer is superfluous.
    – bug
    Apr 25, 2014 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .