HostOnNet Blog

Linux shell – bash, zsh, chsh

Looking for Linux Server Admin or WordPress Expert? We can help.

Most linux systems use bash shell. When you take terminal, what you do is run bash. To see version of bash, run

bash --version

There are other shells, like dash, zsh, omyzsh available as replacement to bash.

View Shell You Are using

To view shell you are using, run

echo $0

Or

echo $SHELL

Example

root@hon-vpn:~# echo $0
-bash
root@hon-vpn:~# echo $SHELL
/bin/bash
root@hon-vpn:~# 

Another method is to run

echo "$$"

That shows PID of shell you are using. To find the program with the PID, run

ps -p "$$"

Example

root@hon-vpn:~# ps -p "$$"
  PID TTY          TIME CMD
 4939 pts/1    00:00:00 bash
root@hon-vpn:~# 

Changing Shell Of A User

Shell of a user is set in /etc/passwd file. To see shell of user root, lets run

root@hon-vpn:~# cat /etc/passwd | grep root
root:x:0:0:root:/root:/bin/bash
root@hon-vpn:~# 

We found user root have shell set to /bin/bash

To change a users shell, run

chsh USERNAME --shell /path/to/shell

Let say i want to set shell for user apache to /bin/bash, run

[root@server1 ~]# chsh apache --shell /bin/bash
Changing shell for apache.
Shell changed.
[root@server1 ~]# 

You can also change shell using usermod command.

Posted in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.