How to change default shell in Linux
How to change default shell in Linux
- You can use command
chsh
to change your default shell, below command changes default shell from bash to zsh
chsh -s $(which zsh)
You need sudo/root password to do this.
- To list available shells in your system
cat /etc/shells
OR
chsh -l
- How to verify if I changed my default shell successfully.
getent passwd yourusername
Note: Your need log out then log in again to enable this change
How about I don’t have sudo/root access or it’s not a local account
Theoretically you can’t change your default shell without sudo/root access, you need to ask someone like IT to do it for you.
But you can try to modify your current shell’s personal configuration file to switch another shell you want.
Below is an example to switch from bash to zsh
-
Update your ~/.bashrc
echo zsh >> ~/.bashrc
-
Open a new terminal or re-login
-
Add below line into .zshrc
export SHELL=/usr/bin/zsh
because some applications may depend on environment variable
SHELL
-
Verify
[j@centos]~% echo $SHELL /usr/bin/zsh [j@centos]~% echo $0 zsh
How to change default shell for another user
sudo chsh -s /usr/bin/zsh username
Change default shell by modifying /etc/passwd
sudo vi /etc/passwd
What command chsh
does is updating file /etc/passwd
, so you also can do it by updating that file directly.