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?

  • Try pressing ctrl+d twice, it should log you out of a terminal as well. – Thom Wiggers Nov 30 '11 at 22:45
  • 2
    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? – Gigamegs Nov 30 '11 at 22:49
  • @Daniel: How can I do that? – Gigamegs Nov 30 '11 at 22:50

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.

  • 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? – Gigamegs Nov 30 '11 at 23:13
  • 1
    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? – Gigamegs 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.

  • 2
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.