Saturday, December 19, 2015

How to change default login shell permanently in linux ?

  
In Red hat Linux the default shell you login to is /bin/bash but in case you want to change the default login shell follow the below procedure

To check the currently logged in shell

# echo $SHELL
/bin/bash

To view all the available shells in your machine

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

You can also view the available shell details from the below file
# less /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

To change the shell temporarily
To do this just provide the full path of the shell you want to use. But this is just a temporary change as next time you switch terminal you will login to the default shell
[root@linuxforfreshers ~]# /bin/sh
sh-4.1#
As you see above my shell prompt changed from /bin/bash to /bin/sh

To change the shell prompt permanently
# chsh -s /bin/sh
Changing shell for root.
Shell changed.
[root@linuxforfreshers ~]#
But as you notice even though our shell was changed successfully but still we see bash shell prompt.

NOTE: To make the changes affect you need to log out and log back in
Using username "root".
root@192.168.8.130's password:
Last login: Fri Mar 21 10:15:03 2014 from 192.168.8.20
-sh-4.1# echo $SHELL
/bin/sh
-sh-4.1#

So now as I try to login I see my default login shell is changed to /bin/sh

Which file is responsible for assigning shell by default?
What if you want next time you create a user, he/she should get different shell and every time you don't change their shell manually

Check the below file
# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes


As you see the SHELL argument has /bin/bash as default. Just change this value to any shell you want to provide for a new user.

No comments:

Post a Comment