Users

The chsh command

Changes a user's login shell, the program that opens when logging in.

Syntax

chsh -s /bin/bash usuarioTry it in the terminal →

Most useful options

-s, --shell <shell>Full path of the new shell. If you do not give it, chsh asks for it
-l, --list-shellsPrints the shells listed in /etc/shells and exits
-h, --helpShows the help and exits
-V, --versionShows the version and exits

Copy-ready examples

$ chsh -llists the shells you can pick without problems.
$ chsh -s /bin/zshchanges your own shell to zsh. If zsh is not installed or is not listed in /etc/shells, it is rejected.
$ sudo chsh -s /bin/bash alumnochanges the shell of another account, alumno, to bash.
$ sudo chsh -s /usr/sbin/nologin alumnowarning: the account will no longer be able to open an interactive shell. Use it only for service accounts or to block access, and undo it with sudo chsh -s /bin/bash alumno.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
chsh: "/bin/fish" is not listed in /etc/shells.The shell is not in /etc/shells. A normal user can only pick the ones listed there; root only gets a warning.Check the list with chsh -l. If the shell is installed, ask the administrator to add it to /etc/shells.
chsh: shell must be a full path nameYou wrote only the shell name, such as zsh, instead of the full path.Use the path: chsh -s /bin/zsh. To find it, run command -v zsh.
chsh: "/bin/nope" does not existThe path does not exist: the shell is not installed or the path is misspelled.Install the shell or correct the path. The valid paths are the ones chsh -l shows.

Typical mistakes

  • For a normal user the shell must appear in /etc/shells. Otherwise chsh rejects it even if the program exists.
  • Without root you cannot change another account's shell: chsh replies that you are not authorized.
  • The change shows at the next login. A terminal that is already open keeps the previous shell.
  • On Debian and Ubuntu, chsh comes from the passwd package (shadow): it has no -l, so read the list with cat /etc/shells, and its error messages differ.

Differences from similar commands

  • usermod: with -s it changes the shell too, but it is meant for managing accounts: groups, expiry and locking.
  • su: opens a session under another identity only while it lasts. chsh changes the shell that will open at the next logins.
  • getent: shows the shell in the last field of /etc/passwd, without changing it.

Related commands

FAQ

How do I see my current shell?

With getent passwd $USER | cut -d: -f7. The last field is the shell recorded in the account. The $SHELL variable may differ if you started another shell inside the session.

Can I set a shell that does not exist?

No. chsh first checks that the path exists and is executable, and changes nothing if it fails.

What is /usr/sbin/nologin for?

For accounts that must not log in interactively. When someone tries to log in, the system closes the session without giving them a shell.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course