On Linux a login shell is a shell given to a user upon login into their user account. Today we will look at how to change the default login shell safely for one specific user.
Change user login shell safely
To set the particular shell, the shell entry must be present in /etc/shells file.
[root@host ~]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/zsh /bin/tcsh /bin/csh
If it is a new user, we can use useradd -s to set the shell for this user.
# useradd -s /bin/bash testuser
To change existing user's shell, below two commands can be used:
# chsh -s /bin/bash testuser # usermod --shell /bin/bash testuser
It is not a safe way to change the user login shell by changeing file /etc/passwd directly. We don't recommend this way.
We can use the following two ways to verify the shell for this user.
# echo $SHELL /bin/bash # cat /etc/passwd | grep testuser testuser:x:8152:9152::/home/testuser:/bin/bash