How/Command to change the login shell for a user – Unix/Linux

We have already discussed one method to change the login shell of a user by changing the shell value in /etc/passwd file by using the command USERMOD. Shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. Here I am explaining one another simple method to change the login shell of a user with help of the command ‘chsh‘.

All shells are listed in /etc/shells, see the example below:

root@crybit [~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/usr/local/cpanel/bin/jailshell
/bin/ftpsh
/usr/local/cpanel/bin/noshell

The ‘chsh‘ command usage with examples:
Syntax:

# chsh [options] [user]

Switches:
1, -s, –shell
Specify your login shell.

2, -l, –list-shells
Print the list of shells listed in /etc/shells and exit.

3, -u, –help
Print a usage message and exit.

4, -v, –version
Print version information and exit.

How to change the login shell of a user?
Syntax:

# chsh -s /new/shell username

Example:

root@crybit [~]# grep crybit /etc/passwd
crybit:x:32011:32012::/home/crybit:/bin/bash
------
root@crybit [~]# chsh -s /sbin/nologin crybit
Changing shell for crybit.
Shell changed.
------
root@crybit [~]# grep crybit /etc/passwd
crybit:x:32011:32012::/home/crybit:/sbin/nologin

That’s it !!! 🙂

Related Links:
Command to find out the current shell
[USERMOD]How to change the shell for an already existing user – Unix/Linux
The usermod

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

Leave a Reply

Your email address will not be published. Required fields are marked *