chsh command

From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search
chsh command in Linux and Unix with examples
chsh command in Linux and Unix with examples

The chsh command in Linux or Unix like systems is used to change user's login shell. If a shell is not given on the command line, chsh prompts for one. This page explains how to change login shell using the chsh command in Linux or Unix systems such as FreeBSD or macOS.

chsh command syntax

The syntax is as follows:

chsh -s /path/to/new/shell
chsh -s /bin/ksh userName

How do I print the list of available shell in my system?

Try the more command or cat command as follows:

cat /etc/shells

Sample outputs from Alpine Linux:

# valid login shells
/bin/sh
/bin/ash
/bin/bash

On certain version of Unix you can pass the -l option to the chsh' that displays the list of shells listed in the /etc/shells file:

chsh -l

Sample outputs:

/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/zsh

How do I change my current login shell from bash to ksh?

Simply type the following command[1] to change your shell to /bin/ksh:

chsh -s /bin/ksh

The system administrator (root user) can change the user's shell as follows:

sudo chsh -s /path/to/newshell username-here

For example, change shell to /bin/sh for maria user as follows:

sudo chsh -s /bin/sh maria

Verification

Use the getent command or grep command on the /etc/passwd file as follows:

getent passwd userName
getent passwd maria
## OR ##
grep -w '^userName' /etc/passwd
grep -w '^maria' /etc/passwd

Sample outputs:

maria:*:1001:1001:web developer account:/home/vivek:/bin/sh

References