• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : How to Change the login shell of the user

by admin

The file /etc/shells the full paths for all the login shells available on the system. So, to set the particular shell, the shell entry must be present in /etc/shells file.

# cat /etc/shells 
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

You can also use the chsh -list or chsh -l command to list out the available shells on the system:

# chsh --list
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

Change login shell at the time of creating user

To set the particular shell at the time of creating user, below command can be used:

# useradd -s [shell] [username]

For example to set the shell of user testuser to /bin/bash :

# useradd -s /bin/bash testuser

Change login shell of existing user

To change existing user’s shell, below command can be used:

# chsh -s [shell] [user]

For example, to change the shell of testuser to /bin/bash using chsh command:

# chsh -s /bin/bash testuser

Another way to change the shell is to use the command usermod. The syntax to change shell of the user is :

# usermod -s [shell] [user]

For Example, to change the shell of testuser to /bin/bash using usermod command:

# usermod -s /bin/bash testuser

Verify

Verify the current login shell of the user with either of the below methods:

# echo $SHELL
/bin/bash
# cat /etc/passwd | grep testuser
testuser:x:8152:9152::/home/testuser:/bin/bash
Note: Non-root users are prompted for their password before the shell is changed. These changes will take effect on the next login.

Filed Under: Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to allow or deny Users to login to VSFTP Server
  2. colrm : command not found
  3. How to allow all traffic from a server using firewalld in CentOS/RHEL
  4. Beginners guide to Kernel Module Configuration in Linux
  5. quotaoff Command Examples in Linux
  6. protonvpn-cli Command Examples in Linux
  7. How to Make User Account Read-Only in CentOS/RHEL 7
  8. uptime: command not found
  9. watch command examples to run a command repeatedly or monitor dynamically changeable files (like /proc/*)
  10. How to make alias command work in bash script or bashrc file

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright