Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Change a User's Login Shell with chsh

chsh lets a user pick another login shell, such as bash or zsh.

VPS and Cloud Servers2 min read2 screenshots

What chsh does

chsh means "change shell". The login shell is the program that starts when a user logs in. Shells differ in features, so people change them to match their work style.

Note: On most Linux systems chsh changes only the login shell. Other account details are changed with usermod. The options below follow the -s use you will see on every system.

Syntax

chsh [options] [username]

Without a user name, chsh changes the shell of the current user. See the options with:

chsh -h
Help output of chsh

The most used option is -s (or --shell), which sets the login shell.

Change the shell

chsh -s /bin/bash username
Changing the login shell

This makes /bin/bash the login shell of username. The shell must be listed in the file /etc/shells. Show that list with:

cat /etc/shells

You can switch your own shell, for example to zsh, with:

chsh -s /bin/zsh

The change works from the next login.

Other account changes

The chsh command is for the shell. Use usermod for the home folder, the primary group and the user ID:

sudo usermod -d /home/new_directory -m username
sudo usermod -g groupname username
sudo usermod -u new_uid username

To create a user with a shell and a home folder at once:

sudo useradd -m -s /bin/bash newuser

Security tips

  • Normal users can change only their own shell. Root can change any.
  • Do not give a user a shell that is not listed in /etc/shells.
  • Take care with the primary group. Putting a user in a group like sudo gives strong rights.
  • A shell such as /usr/sbin/nologin blocks interactive logins for service accounts.

Quick recap

  • chsh -s /path/to/shell username sets the login shell.
  • Check /etc/shells for valid shells.
  • Use usermod for the home folder, groups and IDs.