How to change the shell for an already existing user – Unix/Linux

We can change the shell of a user by using the ‘usermod’ command. Some common types of shells are listed below:
> /bin/bash
> /bin/ksh
> /bin/csh
> /bin/sh
> /sbin/nologin
etc…

We can find out the shell details from the ‘passwd’ file under ‘/etc’ location.

Example:
Display shell details of the user ‘me’

[root@localhost ~]# grep -w me /etc/passwd
me:x:502:502::/home/me:/bin/bash

Shell is : /bin/bash

How to change the shell via command line?
The usermod command with switch ‘s’ is used to change the current shell of a user. Other useful usermod switches.

Example:

[root@localhost ~]# usermod -s /sbin/nologin me
[root@localhost ~]# grep -w me /etc/passwd
me:x:502:502::/home/me:/sbin/nologin

The shell changed to “/sbin/nologin”

That’s it!! 🙂

Related Links:
groupdel, groupmems, groupmod, useradd , usermod

Post navigation

Arunlal A

Engineer. Linux enthusiast. Traveller. DevOps learner and practitioner. I enjoy working with Linux, DevOps, automation, and technology while exploring new places along the way. I use this space to share my experiences, learnings, experiments, and things I discover along the journey. Whether you're a seasoned DevOps professional or just getting started, let's connect, learn, and grow together. Happy coding, automating, and deploying!

2 thoughts on “How to change the shell for an already existing user – Unix/Linux”

Leave a Reply

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