Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I run zsh on my server and I want to alias the exit command, because whenever I try to terminate my SSH session I must exit from zsh and exit from bash.

I tried alias exit='exit;exit' to no avail.

I don't want to change how I start zsh but I think it's not a very good solution. I've appended zsh to /etc/profile.

How can avoid to type exit twice to terminate my SSH session?

share|improve this question
Try pressing ctrl+d twice, it should log you out of a terminal as well. – Thom Wiggers Nov 30 '11 at 22:45
To clarify, bash is your login shell and you run zsh by manually starting it? Have you considered making zsh your login shell or running it using the exec built-in, replacing the bash process? – Daniel Beck Nov 30 '11 at 22:46
When I want to change how to start zsh do I have to append zsh to ~/.bashrc? How can I completley replace bash? – Betterdev Nov 30 '11 at 22:49
@Daniel: How can I do that? – Betterdev Nov 30 '11 at 22:50
up vote 6 down vote accepted

bash is the default login shell of your account on that system. To change it, do what @KevinPanko suggests. Then bash won't start, only zsh. Given that, through /etc/profile, you're always starting zsh at the moment (and not just sometimes), that would probably the best way to do it.

Alternatively, you can use the exec built-in command of bash to replace your bash process. man bash states:

exec ... [command [arguments]]

If command is specified, it replaces the shell. No new process is created. The arguments become the arguments to command.

So you can run zsh like this:

exec zsh

Afterwards, if you exit zsh, you exit the only shell you're running, and quit immediately.

share|improve this answer
When I use chsh can I break something? Can I start a SSH session when I break something, I mean when bash or zsh and both doesn't load anymore? Is there a failsafe to SSH? – Betterdev Nov 30 '11 at 23:13
You can give SSH a command to run: ssh -t hostname /bin/bash – Kevin Panko Nov 30 '11 at 23:20
@jitamaro direct access to the machine or log in as a different user is your fail safe. If you actually manage to mess up your shell binary, you'll have been making stupid mistakes as root and deserve to restore from backup ;) – Daniel Beck Nov 30 '11 at 23:21
@Dainiel: I don't have physical access to that box and I have only one user (root). It's a good practise to create another user or give SSH a command to run? – Betterdev Nov 30 '11 at 23:26
@jitamaro do not run as root unless you absolutely have to and know what you're doing. No offence, but it sounds like you might profit from reading a tutorial or two about Linux use..? That'll explain why multiple users are a good thing, – Daniel Beck Nov 30 '11 at 23:32

The chsh command lets you change the login shell on your account.

You might need to add /bin/zsh to your /etc/shells file if it is not there already.

share|improve this answer
If the server you connect to uses LDAP or similar, you'll have to use the ypchsh command instead. – Erik Dec 6 '12 at 22:59

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.