How do I change my default shell on a AWS instance?

123

44

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!

Shripad Krishna

Posted 2011-01-11T11:31:38.820

Reputation: 1 331

Answers

160

Try using the chsh command.

e.g.

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.

John T

Posted 2011-01-11T11:31:38.820

Reputation: 149 037

5I use a lightly different version sudo chsh -s $(which zsh) $(whoami) – SergioAraujo – 2015-04-30T19:37:14.160

getting a chsh: /usr/local/bin/zsh: non-standard shell message – Yar – 2016-07-01T16:26:16.133

Since chsh -s /bin/zsh emits a password prompt, and the default AWS image gives you a ec2-user with a ssh key (don't know password) I had to do sudo passwd root, then give a new password, then sudo passwd ec2-user, then I could to chsh -s /bin/zsh with the ec2-user's password (you do not need to sudo chsh) – Colin D – 2019-09-05T21:22:56.457

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 :) – Shripad Krishna – 2011-01-11T11:45:28.543

3@Paddy if you are root you can change it for another user by running chsh -s /bin/zsh username. – John T – 2011-01-11T11:47:21.023

Awesome :) Much easier. Thanks for that info too. – Shripad Krishna – 2011-01-11T11:48:00.943

I'm getting: chsh: /usr/local/bin/zsh is an invalid shell – Jürgen Paul – 2013-02-26T04:13:50.737

3@We are the World: You need to add /usr/local/bin/zsh as a new line to /etc/shells – Nate Parsons – 2013-06-04T17:54:48.560

20

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.

Georgii Oleinikov

Posted 2011-01-11T11:31:38.820

Reputation: 301

6It's better to use chsh, but if you're really going to edit /etc/passwd by hand, at least use the vipw command. – Valmiky Arquissandas – 2014-08-14T02:58:29.950

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? – Georgii Oleinikov – 2014-08-14T16:44:19.117

Don't touch /etc/passwd. There are better ways to do this that do not require messing with the passwd tool! – Andrew – 2017-09-12T18:23:12.300

9

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)

chau giang

Posted 2011-01-11T11:31:38.820

Reputation: 193

Thanks! This worked for AWS AMI :) – Mayura – 2019-10-20T23:31:01.807

With lchsh, just do sudo lchsh -i ec2-user. – superhawk610 – 2020-02-22T00:32:29.633

5

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.

Peace.

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

Ben

Posted 2011-01-11T11:31:38.820

Reputation: 51

You have the rep you need now. :P – pradyunsg – 2016-03-21T08:43:30.323

0

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 \
  ~/.oh-my-zsh/custom/plugins/fast-syntax-highlighting

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

OWADVL

Posted 2011-01-11T11:31:38.820

Reputation: 157