Updated: 4 November 2026 · Applies to: Ubuntu 26.04 (passwd 4.17.4, sudo-rs 0.2.13), Debian 13 and AlmaLinux 10.2 (util-linux 2.40.2), tested; AlmaLinux and Rocky Linux 9 and Fedora 44 package names checked

To change your own default shell in Linux, run chsh -s with the full path of the new shell and enter your password, then log out and back in:

chsh -s /usr/bin/zsh

To change another user's shell, run it as root with the user name at the end, or use usermod:

sudo chsh -s /usr/bin/zsh alice
sudo usermod -s /usr/bin/zsh alice

Both commands change the shell field in /etc/passwd. The change applies to the next login, not to sessions that are already open. If you only want to act as another user for a while, you do not need to change any shell: see "Switch to another user" below.

1. Install the shell and find its path

  1. Install the shell, for example zsh or fish:
    sudo apt install zsh fish      # Debian, Ubuntu
    sudo dnf install zsh           # AlmaLinux, Rocky Linux, Fedora
  2. List the valid login shells. The package adds its own entries, so after the install above Ubuntu 26.04 showed:
    $ cat /etc/shells
    # /etc/shells: valid login shells
    /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
    On AlmaLinux, Rocky Linux and Fedora, chsh -l prints the same list. Use a path from this list, or command -v zsh to find it.

2. Change the shell with chsh

  • Your own shell: chsh -s /usr/bin/zsh. It asks for your password, not for root. Run chsh without options to be asked for the new value: Login Shell [/bin/bash]:.
  • Another user's shell (as root): sudo chsh -s /usr/bin/zsh alice. On Debian and Ubuntu it prints nothing on success; on AlmaLinux it prints Changing shell for alice. and Shell changed.
  • chsh is missing on AlmaLinux or Rocky Linux 9: it is in a separate package, sudo dnf install util-linux-user. On version 10 and Fedora 44 it is part of util-linux; on Debian and Ubuntu it comes with the passwd package.

3. Change the shell with usermod or vipw

sudo usermod -s /bin/bash alice does the same as root's chsh and is handy in scripts. To edit the file by hand, use sudo vipw rather than opening /etc/passwd directly: it locks the file while you edit. The shell is the last field of the user's line:

alice:x:1001:1001::/home/alice:/usr/bin/zsh

4. Check the result

$ getent passwd alice
alice:x:1001:1001::/home/alice:/usr/bin/zsh

After you log in again, echo $SHELL shows your login shell and ps -o comm= -p $$ shows the shell you are running right now. They can differ: in our test, after exec zsh in a bash login, ps showed zsh while $SHELL still said /bin/bash. To try a shell first, just type zsh (and exit to go back); exec zsh replaces the current shell for this session only.

5. Set the default shell for new users

The default depends on the tool. On Debian 13 and Ubuntu 26.04, useradd -D shows SHELL=/bin/sh, while adduser gives new users /bin/bash. On AlmaLinux 10, useradd uses /bin/bash. To change the useradd default, or to pick the shell when you create a user:

sudo useradd -D -s /bin/bash          # default for future useradd accounts
sudo useradd -m -s /usr/bin/zsh bob   # one new user

Rules and error messages

  • A normal user can only choose a shell listed in /etc/shells. Ubuntu answers chsh: /usr/local/bin/foo is an invalid shell; AlmaLinux answers chsh: "/usr/local/bin/foo" does not exist for a missing file.
  • Root may set a shell that is not listed; Ubuntu then only warns (chsh: Warning: /usr/local/bin/foo is an invalid shell). Do not do this for real accounts: a missing shell means the user cannot log in.
  • A user cannot change someone else's shell: You may not change the shell for 'root'. On Debian and Ubuntu a user whose current shell is not in /etc/shells cannot change it either and gets the same message with their own name; root has to fix it.

Fix "chsh: user does not exist"

  • chsh: user 'nosuch' does not exist (Debian, Ubuntu) or chsh: user "nosuch" does not exist. (AlmaLinux): the name is wrong. Check it with getent passwd NAME or whoami.
  • chsh: user 'ldapbob' does not exist in /etc/passwd: the account exists, but it comes from a directory such as LDAP or Active Directory (through SSSD), not from the local files. chsh and usermod only edit local files; in our test usermod -s just answered usermod: no changes. Change the login shell attribute in the directory instead, or override it on this server in /etc/sssd/sssd.conf with override_shell = /usr/bin/zsh (in the [nss] section or the domain section), then run sudo systemctl restart sssd and clear its cache with sudo sss_cache -E. According to the SSSD manual, default_shell only applies when the directory returns no shell.

Switch to another user

  • su - alice: start a login shell as alice (asks for alice's password). The dash matters: in our test su alice stayed in /root, while su - alice started in /home/alice with alice's environment. More in the difference between su and su -.
  • sudo -iu alice: the same with your own password, if you have sudo rights (see how to add a user to sudo on Debian). As root, runuser -u alice -- COMMAND runs one command without a password. Type exit to return to your own account.
  • Service accounts such as www-data have the shell /usr/sbin/nologin, so su - www-data answers This account is currently not available. Run a shell for them explicitly: sudo -u www-data bash or, as root, su -s /bin/bash www-data.
  • To switch without a password in a controlled way, see how to switch (su) to another user account without password.

SSH as a different user

Put the user name before the host, or use -l:

ssh alice@server.example.com
ssh -l alice server.example.com

To always use a certain user for a server, add a block to ~/.ssh/config; ssh -G shows what ssh will use without connecting:

Host web1
    HostName 203.0.113.10
    User deploy
    Port 2222

$ ssh -G web1 | grep -E '^(user|hostname|port) '
user deploy
hostname 203.0.113.10
port 2222

Many servers block direct root logins over SSH (see how to disable root user login via SSH): log in as your own user and then use sudo -i or su -. If the server listens on another port, see the default SSH port and how to change it.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket