Change user's default shell

Reasons

  1. To block or disable normal user logins in Linux using a nologin shell.

  2. To use a shell wrapper script or program to login user commands before they are sent to a shell for execution.

  3. To meet a user’s demands (wants to use a specific shell), especially those with administrative rights.

Default shells

cat /etc/shells

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

Ways to change

  1. usermod utility

usermodis a utility for modifying a user’s account details, stored in the /etc/passwd file and the -s or --shell option is used to change the user’s login shell.

usermod --shell /bin/bash $USER
grep $USER /etc/passwd
  1. chsh utility

chsh is a command line utility for changing a login shell with the -s or --shell option.

chsh --shell /bin/sh $USER
grep $USER /etc/passwd
  1. /etc/passwd file

In this method, simply open the /etc/passwd file using any command line text editor and change the specific users shell.

vi /etc/passwd

When done editing, save and close the file.

Last updated