Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 am using my school's computers and would like to use zsh instead of bash. I'd like to make it default, but I cannot run a command such as $ chsh -s $(which zsh) because I don't have admin privileges.

Is there a way I can put something in my .bashrc or something that automatically calls zsh when it opens as a workaround? To clarify, zsh is already installed. Thanks for your help.

share|improve this question

migrated from stackoverflow.com Jun 10 '14 at 14:22

This question came from our site for professional and enthusiast programmers.

Yes, just add zsh on the .bashrc file. Logout and login and done! – fedorqui Jun 10 '14 at 13:45
Sorry about that. But to finish the question, I just put zsh on the first line? – goodcow Jun 10 '14 at 13:47
Thank you, that seemed to work! – goodcow Jun 10 '14 at 13:48
Placing zsh in .bashrc would make it always execute even when bash is called explicitly. Better place it in .bash_profile instead. – konsolebox Jun 10 '14 at 13:51
up vote 23 down vote accepted

Create .bash_profile in your home directory and add these lines:

export SHELL=/bin/zsh
exec /bin/zsh -l

Update: .profile may work as a general solution when default shell is not bash. I'm not sure if .profile may be called by Zsh as well that it could go redundant but we can do it safely with a simple check:

export SHELL=/bin/zsh
[ -z "$ZSH_VERSION" ] && exec /bin/zsh -l

We can also use which to get the dynamic path of zsh which relies on the value of $PATH:

export SHELL=`which zsh`
[ -z "$ZSH_VERSION" ] && exec "$SHELL" -l
share|improve this answer
What if a Linux admin (root) changes your default shell to something other than bash (but not zsh), for example ksh? Then .bash_profile won't get referenced. How about put this in .profile instead? – Joshua Huber Jun 11 '14 at 17:10
@JoshuaHuber Last test I made, .profile didn't work. Also wouldn't .profile be called by Zsh? It could go redundant. Haven't checked that yet though. (Update: It did work now, not sure what mistake I made before.) Any thoughts about possible drawbacks with using .profile? – konsolebox Jun 11 '14 at 17:10
@konsolebox Bash only sources .profile if .bash_profile doesn't exist (unless you manually source it from .bash_profile, of course). Specifically, bash sources the first one of the files [.bash_profile > .bash_login > .profile] it finds. It only looks for .profile as a POSIX (Bourne shell) compatibility feature. – pyrocrasty Apr 27 at 11:28
@pyrocrasty Indeed. Just as said in the manual: "After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable." – konsolebox Apr 27 at 17:06

Normally you can use chsh as a non-root user. But it's occasionally disabled, usually in sites that use some form of networked user database like NIS and LDAP. There might be a ypchsh (NIS) or chsh.ldap (LDAP) instead.

chsh will also usually allow only some approved shells, typically the ones listed in /etc/shells.

If you can't use chsh or its variants at your site, then arrange for your login shell to exec your favorite shell, and set the SHELL variable to point to your favourite shell.

  • If your login shell is sh, dash or ksh: the file you need to edit is ~/.profile. Beware that this file is read at the beginning of an interactive session as well as by some non-interactive session startup scripts (e.g. for X11 sessions), so you need to take care: only call exec (which replaces the current process) when the current shell is interactive. Except for the Bourne shell (the /bin/sh of Solaris 10 and before), you can tell that a shell is interactive by the presence of i in the option list ($-).

    if [ -x /bin/zsh ]; then
    if [ -n "$preferred_shell" ]; then
      case $- in
        *i*) SHELL=$preferred_shell; export SHELL; exec "$preferred_shell";;

    If you want zsh to read your .zprofile, pass the -l option.

  • If your login shell is bash, you can proceed as above. Alternatively, you may put these commands in ~/.bash_profile. Most session startup scripts only read ~/.profile and not ~/.bash_profile, but I've seen some that run under bash and read .bash_profile, so even there you should be careful not to call exec in a non-interactive shell.

  • If your login shell is csh or tcsh, see an example in Changing the default shell without chsh or administrator priviledges

share|improve this answer

I believe that the command, chsh is for this very purpose. Although, I'm not sure that every Linux/Unix distro support that. Check the man page of chsh.

share|improve this answer
Some systems also have it as passwd -s. – Stéphane Chazelas Dec 18 '15 at 9:49

If you can't run chsh because you don't have admin privileges, talk to someone who does.

Most likely you can't use chsh as non-root because the system you're using is configured so that chsh wouldn't work, for example because the system uses NIS or LDAP rather than just the /etc/passwd file. Or perhaps your system's administrator just wants to maintain some control.

The procedure for changing your shell depends on your organization's policies. There may be a local command that does what chsh normally does. Or you may need to submit a support ticket requesting a shell change.

Most of the other answers are good, but if your administrators are reasonably responsive you might not want to bother hacking your startup scripts. I'd probably just invoke zsh -l manually after logging in until the administrator gets around to updating my account.

Another thing to keep in mind: Sometimes different shells can use the same startup files. For example, sh and bash can both execute $HOME/.profile, and csh and tcsh can both execute $HOME/.login and $HOME/.cshrc (though shell-specific startup files like .bashrc, .bash_profile, and .tcshrc can override those). If your default shell is /bin/csh and you want to use /bin/tcsh, updating your .login to invoke /bin/tcsh -l could create an infinite loop. zsh doesn't happen to execute bash-specific startup files, so that's not an issue for you.

Most shells set variables that identify which shell you're running ($BASH_VERSION, $tcsh, $ZSH_VERSION). If you're going to write startup code to invoke your preferred shell, it's not a bad idea to enclose it in an if so it's executed only if you're not already running that shell. Using the code from konsolebox's answer:

if [ "${ZSH_VERSION:-unset}" = "unset" ] ; then
    export SHELL=/bin/zsh
    exec /bin/zsh -l

(The added complication of checking "${ZSH_VERSION:-unset}" rather than just "$ZSH_VERSION" allows for the possibility that you've done set -o unset, an option that causes a reference to an undefined variable to be an error.)

share|improve this answer

I do not think the provided answer actually makes zsh the default shell. It simple changes the shell to zsh as soon as user logs in to his/her default shell. User will still login to its DEFAULT SHELL but with this, shell will change to zsh

To change the default shell use:

usermod -s /path/to/shell username 

You should be root to do that.

Otherwise the above workaround will come handy.

Added from comment

chsh -s /path/to/zsh  # considered as standard as compared to usermod

and it can be invoked by user for him/herself.

share|improve this answer
The question pretty clearly states that modifying the system user database (the bit you need root to do in this answer) is not an option. – Caleb Jun 10 '14 at 14:37
chsh -s /path/to/zsh is more standard and usually (but not always) doesn't require root access, unlike usermod which always does. So your answer has more problems than what the question already states as not working. – Gilles Jun 10 '14 at 23:09

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.