TechEarl

How to Change a User's Login Shell on Linux (chsh)

Change a user's default login shell with chsh or usermod, check the valid shells in /etc/shells, and see the current shell from /etc/passwd.

Ishan Karunaratne⏱️ 3 min readUpdated
Share thisCopied
Change a Linux user's login shell with chsh or usermod, the valid shells in /etc/shells, and how to read the current one from /etc/passwd.

The login shell is the last field of a user's /etc/passwd line. Change another user's shell as root with chsh -s:

bash
sudo chsh -s /usr/bin/zsh deploy
Root terminal running chsh -s /usr/bin/zsh deploy, then getent passwd deploy showing the final field changed to /usr/bin/zsh.
chsh -s sets the login shell; the last colon field of the passwd entry confirms the change.

Change your own shell

Without a username, chsh changes your own shell (it prompts for your password):

bash
chsh -s /usr/bin/zsh

usermod does the same thing as root and is the scriptable choice:

bash
sudo usermod -s /usr/bin/zsh deploy

The change takes effect at the next login, not in the current shell. To try a shell right now without making it permanent, just run it: zsh.

The shell has to be in /etc/shells

chsh only accepts shells listed in /etc/shells. If yours is missing, chsh refuses it:

bash
cat /etc/shells           # the allowed login shells
which zsh                 # where the shell actually is

If zsh is installed but not listed, add its path to /etc/shells (as root) and chsh will then accept it. usermod -s does not enforce /etc/shells, which is a footgun: it will happily set a path that does not exist and lock the user out of logging in.

Check the current shell

bash
getent passwd deploy | cut -d: -f7     # the shell field for one user
echo "$SHELL"                          # your own current login shell

A nologin shell disables interactive login

Setting the shell to nologin is how you keep a service account from being logged into, while it can still own files and run daemons:

bash
sudo usermod -s /usr/sbin/nologin appsvc

This is also part of locking an account fully.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxchshusermodShellSystem Administration

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts