I want to change my shell from the default bash shell to zsh on my Amazon EC2 instances. How do I go about doing it? Thanks!

6 Answers 6


Try using the chsh command.


chsh -s /bin/zsh

You can confirm the location of zsh by running whereis zsh, or alternatively simply run

chsh -s $(which zsh)

If you want to change the shell for a user account other than the one you're logged into, you'll need to run it as root, so to change john's shell, do:

sudo chsh -s $(which zsh) john

Note that you'll need to log out and log back in for the change to go into effect. If you're using Gnome or some other window manager, you'll need to completely log out of that session as well—simply closing and opening your terminal is insufficient.

  • I did try that, but with the root user!! My AMI Image has ubuntu rather than root. Had to switch to ubuntu user to change the shell! Thanks for the hint :) Commented Jan 11, 2011 at 11:45
  • 3
    @Paddy if you are root you can change it for another user by running chsh -s /bin/zsh username.
    – user1931
    Commented Jan 11, 2011 at 11:47
  • Awesome :) Much easier. Thanks for that info too. Commented Jan 11, 2011 at 11:48
  • 3
    @We are the World: You need to add /usr/local/bin/zsh as a new line to /etc/shells Commented Jun 4, 2013 at 17:54
  • 7
    I use a lightly different version sudo chsh -s $(which zsh) $(whoami) Commented Apr 30, 2015 at 19:37

Open /etc/passwd:

sudo vi /etc/passwd

Find the line with your username:

username:x:1634231:100:Your Name:/home/username:/bin/bash

and replace bash with zsh:

username:x:1634231:100:Your Name:/home/username:/bin/zsh

Log out and log in back for the changes to take effect.

  • 7
    It's better to use chsh, but if you're really going to edit /etc/passwd by hand, at least use the vipw command. Commented Aug 14, 2014 at 2:58
  • I don't have chsh on my machine. Also, for some weird reason my /etc/passwd file is regularly being overwritten by the default one. Do you know why this could be happening? Commented Aug 14, 2014 at 16:44
  • Don't touch /etc/passwd. There are better ways to do this that do not require messing with the passwd tool!
    – Andrew
    Commented Sep 12, 2017 at 18:23
  • 1
    On Ubuntu AMIs it is not possible to use chsh for ubuntu user since it requires a password. Editing /etc/passwd file does the trick. More info here.
    – makons
    Commented Feb 19, 2021 at 10:59

I came here to just add more additional information. If you have troubles when install zsh in Amazon Linux AMI by Amazon, like when you run:

sudo chsh $(which zsh) : // chsh command not found

Then you should install util-linux-user:

sudo yum install util-linux-user

(by default Amazon Linux AMI only has lchsh, but I can not figure how it work).

Then run the following command, it should work:

sudo chsh -s $(which zsh) $(whoami)
  • 3
    Thanks! This worked for AWS AMI :)
    – Mayura
    Commented Oct 20, 2019 at 23:31
  • 2
    With lchsh, just do sudo lchsh -i ec2-user. Commented Feb 22, 2020 at 0:32
  • 1
    You can skip interactive. which git-shell | lchsh git for example. Commented Jul 2, 2020 at 21:50

On Ubuntu, inside GNOME terminal, making changes via chsh won't have the expected effect...

To get over this problem, do this:

  • Right click in terminal
  • Profiles -> Profile Preferences
  • Under "Title and Command" tab, tick "Run a custom command instead of my shell" and provide the path to zsh executable.
  • Restart Terminal.


P.S. Don't have 10 reputation to post images, so all texty instructions. :)

  • You have the rep you need now. :P
    – pradyunsg
    Commented Mar 21, 2016 at 8:43

one line

sudo chsh -s $(which zsh) $(whoami)

Extra Info: after that you'll probably want to do this ones

git clone https://github.com/zdharma/fast-syntax-highlighting.git \

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

nano ~/.zshrc 

find plugins=(git) Append zsh-autosuggestions & zsh-syntax-highlighting to plugins() like this

plugins=(git zsh-autosuggestions fast-syntax-highlighting)

source ~/.zshrc

I had an ubuntu 18.04 EC2 instance. But, when i tried doing:

ubuntu@ip-xxx:~$ chsh -s /bin/zsh         
chsh: PAM: Authentication failure

I got a password prompt, which failed with auth error because quite frankly I'm not sure of what to put there for sudo user.

So, I tried adding sudo and command didn't give any error. But, when i ssh'ed later, I still got BASH as default SHELL.

What worked for me was the below command:

ubuntu@ip-xxx:~$ sudo chsh -s $(which zsh) $(whoami)

This changed the default shell for current user and it stayed that way for each time I ssh'ed into the machine.

Success! :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .