• 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. How to monitor NVME drives on Centos 6
  2. “mount.nfs: access denied by server while mounting” – how to resolve
  3. Linux OS Service ‘anacron’
  4. chkconfig Command Examples in Linux
  5. How to block non-root user from creating crontab entry in Linux
  6. “sudo: /etc/sudoers is world writable” – How to correct the permissions of sudoers file
  7. How to disable IPv6 on CentOS / RHEL 7
  8. How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  9. How to change the path of the auditd log file /var/log/audit/audit.log
  10. CentOS / RHEL : Exclusion with Yum For Kernel Updates

You May Also Like

Primary Sidebar

Recent Posts

  • qemu-system-x86_64: command not found
  • timedatectl: command not found
  • mpirun.openmpi: command not found
  • startkde: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright