I run zsh from bash after connecting SSH – how can I exit both with only one command?

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?


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.


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.