Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

If I log in to a system over ssh, I can use the default shell with a simple ssh user@host, or specify something like ssh user@host 'bash --norc --noprofile' or ssh user@host ksh.

Is it possible to have similar behaviour when logging in on a local terminal, ie one where my terminal is connected directly to the system and I'm prompted for a username?

The specific usage scenario is running screen at login time, where a duff config option will prevent screen starting, and thus prevent the login succeeding. If I have ssh access, I can log in and run specific commands to fix things, but if I only have terminal access, I can't see how I could fix things up.

share|improve this question

You could copy the entry for user in /etc/passwd and change (a) the name from user to e.g. user_mod_shell, and (b) the default shell. The "who am i" chaos (probably without real problems) may be reduced by setting USER in the start processes.

share|improve this answer
I don't follow. So the result here would be two users, one for normal use, and one that solely exists for clearing up a login mess that the first had gotten itself into? – me_and May 17 '13 at 13:02
@me_and No you would have several names for the same user, one name for each shell. For each user name a different shell would be started. – Hauke Laging May 17 '13 at 13:33
exactly - also mentioned here: unix.stackexchange.com/questions/74961/… – peterph May 17 '13 at 14:17
Multiple entries with the same UID, then? Cunning! – me_and May 22 '13 at 20:17

Put your terminal multiplexer (be it tmux, screen or something else) into your shell's initialization, but do not exec it (which one would probably do) - that will jump back into shell if anything goes wrong in the terminal multiplexer.

To make it more user friendly, you can use the suggestion from comment by @EvanTeitelman and actually run multiplexer && exit, which will quit the session if the multiplexer exits normally.

share|improve this answer
Nice idea, but I'd prefer to avoid giving the user two shells to break out of in the normal use case. – me_and May 17 '13 at 13:01
You could do this: screen && exit. That way, if screen runs sucessfully, the shell will exit. – Evan Teitelman May 17 '13 at 13:19

Eventually, we went with having the .bash_profile run screen if and only if the variable $SSH_CONNECTION was set. That means the normal use case (logging in via ssh) gets screen (and we can work around that by specifying bash --noprofile as the command to run on login), and for console connections we just get a regular session.

Of course, if we hose things somehow such that screen is executed on every login, we're still hosed. But there's no way of making this utterly foolproof.

share|improve this answer

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.