Change Default Shell in Linux: 5 Easy Steps, 4 Mistakes

To change default shell in Linux, run chsh -s /path/to/shell and log in again. The command, the checks it does, and even whether it is installed differ between distributions, and one mistake as root can leave a user with a shell that does not exist. I ran every step on 22 November 2026 in an Ubuntu 24.04.5 container (chsh from the passwd package) and a Fedora 43 container (chsh from util-linux 2.41.6), switching a test user called dev between bash, zsh and fish.

Step 1: see which shells are allowed

/etc/shells lists the valid login shells. Installing a shell package adds it there:

$ cat /etc/shells        # Ubuntu 24.04 after installing zsh and fish
/bin/sh
/usr/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/usr/bin/dash
/usr/bin/fish
/bin/zsh
/usr/bin/zsh
/usr/bin/zsh

On Fedora, util-linux's chsh has a -l, --list-shells option for the same list (see its --help below); the Ubuntu chsh has no such option. Before you change default shell settings, also note the current value: your login shell is the last field of your passwd entry.

$ getent passwd dev
dev:x:1001:1001::/home/dev:/bin/bash

Step 2: make sure chsh exists (Fedora)

$ command -v chsh || echo "chsh: not installed"
chsh: not installed
$ dnf -y install util-linux-user; rpm -qf $(command -v chsh)
util-linux-2.41.6-1.fc43.x86_64

The Fedora container image had no chsh at all until util-linux-user was installed. On Ubuntu it is part of the base passwd package.

Step 3: change default shell as a normal user

The normal way to change default shell is chsh -s with the full path from /etc/shells. It asks for your own password:

$ chsh -s /usr/bin/zsh
Changing shell for dev.
Password:
Shell changed.
$ getent passwd dev | cut -d: -f7
/usr/bin/zsh

That output is from Fedora; Ubuntu asks for the password and prints nothing on success. A normal user cannot pick a shell outside the list on either system, which protects users from locking themselves out:

chsh: /usr/local/bin/myfish is an invalid shell                 # Ubuntu
chsh: "/usr/local/bin/myfish" is not listed in /etc/shells.     # Fedora
Use chsh -l to see list.

Step 4: log in again, and check

The change is written to /etc/passwd and used at the next login. Your open terminal keeps its old shell and its old $SHELL. A fresh login shows the new one:

$ su - dev -c "echo \$SHELL; ps -o comm= -p \$fish_pid"
/usr/bin/fish
fish

A small proof from the lab that the login really runs the new shell: my first test command used bash's $$, and fish refused it with fish: $$ is not the pid. In fish, please use $fish_pid. Remember that when you move to fish: scripts with a bash shebang keep working, but one-liners you type are now fish syntax.

Changing the shell for another user (root): Ubuntu does not stop you

Change default shell as root: Ubuntu chsh accepts zsh without a path and a missing tcsh, Fedora chsh refuses both
Lab: the same chsh mistakes as root on Ubuntu 24.04 and Fedora 43.

When root needs to change default shell for another account, the two chsh implementations behave very differently. Ubuntu warns and then writes the invalid value anyway, with exit code 0:

# Ubuntu 24.04
$ chsh -s zsh dev; getent passwd dev | cut -d: -f7
chsh: Warning: zsh does not exist
zsh
$ chsh -s /usr/bin/tcsh dev; getent passwd dev | cut -d: -f7
chsh: Warning: /usr/bin/tcsh does not exist
/usr/bin/tcsh

Both values would break the next login of dev: one is not a path, the other is not installed. Fedora refuses both and leaves the old shell in place:

# Fedora 43
$ chsh -s zsh dev
chsh: shell must be a full path name
$ chsh -s /usr/bin/tcsh dev
chsh: "/usr/bin/tcsh" does not exist

Fedora does accept a shell that exists but is not in /etc/shells, with a warning. usermod -s is the other root tool; it changed the field in the lab without checking /etc/shells on either system. So when you change default shell for someone else, always check the result with getent passwd before they log out.

Disabling logins with nologin

Setting the shell to /usr/sbin/nologin is the standard way to keep an account (for a service, or a user who left) without allowing interactive logins:

$ getent passwd dev | cut -d: -f7
/usr/sbin/nologin
$ su - dev -c id
This account is currently not available.
$ su -s /bin/bash dev -c id
uid=1001(dev) gid=1001(dev) groups=1001(dev)

Note the last line: root can still run commands as that user by naming a shell with su -s. nologin blocks logins, not root.

When you cannot change default shell with chsh

On some systems users are not allowed to change their shell, or accounts come from LDAP or Active Directory, where chsh only touches the local file. A common workaround is to start the other shell from your ~/.bashrc for interactive sessions, for example [ -t 1 ] && command -v zsh >/dev/null && exec zsh. Keep the test for the terminal and for the binary, so a missing zsh or a script run over ssh host cmd does not break your logins.

Which shell should you switch to?

Bash stays the safe default on servers: every distribution has it and most scripts and documentation assume it. Zsh is close enough to bash that your habits carry over, and adds better completion and history options, which is why people change default shell to zsh more than to anything else. Fish is the friendliest out of the box, with suggestions and colours and no configuration, but its syntax is its own, as the lab error above showed. My rule: change default shell for your own interactive account freely, and leave service accounts and root on bash.

Change default shell: quick checklist

  1. Install the shell first (apt install zsh, dnf install fish) and confirm it appears in /etc/shells.
  2. Use the full path: chsh -s /usr/bin/zsh.
  3. Keep your current session open, start a new login and check echo $SHELL.
  4. As root on Ubuntu, read the warnings: chsh writes the value even when it is wrong.
  5. Use /usr/sbin/nologin to disable accounts, not a random path.

If zsh is where you are heading, the post on zsh tips and configuration covers the first-run wizard and Oh My Zsh, and portable shell scripts explains why your scripts should not depend on your login shell. The options of the util-linux version are in the chsh(1) man page.

Comments

Popular posts from this blog

Linux Desktop Frozen? 5 Proven Fixes Before a Hard Reboot

Minecraft Bedrock on Linux: 4 Proven Ways to Play in 2026

DXVK in Wine on Linux: 7 Easy Setup Steps, Tested