- Ubuntu Wiki
- Short Description of the main shells
- Why change your shell
- Deciding on a shell
- How to Change Shells
- Temporarily changing your shell for the session you are in
- Changing your login shell which is permanent
- interactive method
- non-interactive method
- More information
- 3 Ways to Change a Users Default Shell in Linux
- 1. usermod Utility
- 2. chsh Utility
- 3. Change User Shell in /etc/passwd File
- What is default shell for terminal?
- 5 Answers 5
Ubuntu Wiki
A shell is a program that provides the traditional, text-only user interface for Unix-like operating systems. Its primary function is to read commands that are typed into a console (i.e., an all-text display mode) or terminal window (an all-text window) in a GUI (graphical user interface) and then execute (i.e., run) them.
Although bash, the default shell on many Debian based Linux distros like Ubuntu and Linux Mint, is highly versatile and can be used for almost anything, each shell has its own characteristics and there might be situations in which it is preferable to use some other shell, such as ash, csh, ksh, sh or zsh. For example, the csh shell has a syntax that resembles that of the highly popular C programming language, and thus it is sometimes preferred by programmers.
Short Description of the main shells
Bourne: the standard default shell for non root users in FreeBSD. You can read about the shell by looking at the «man sh» pages. Uses abbreviation sh.
Korn: a shell developed by AT &T. You can read more about it by looking at the «man ksh93» pages. Uses abbreviation ksh or ksh93.
Bash: The Bourne Again SHell. You can read about it in the «man bash» pages. Uses abbreviation bash.
Z-Shell: The Z shell. You can read about it by looking at the «man zsh» pages. Uses the abbreviation zsh.
C-Shell: The C shell. You can read about it by looking at the «man csh» pages. Uses the abbreviation csh.
TC-Shell: Basically the same thing as above. They are a little bit different, but not very much so they now fall into the same category. You can read about it by looking at the «man tcsh» pages. Uses the abbreviation tcsh.
How to find out what shell you are running:
/bin/sh : This is the Bourne shell.
/bin/ksh93 : This is the Korn shell.
/bin/bash : This is the Bash shell.
/bin/zsh : This is the Z shell.
/bin/csh : This is the C Shell.
/bin/tcsh : This is the TC Shell.
Next Check on your Valid login Shells
Important Note: You May not have all of these installed on your system right now. The way I checked If a shell was installed my system was by looking to see if I had man pages for a particular shell. I will use csh as an example. Type this into your terminal.
If you don’t have any man pages then there is a high probability you don’t have this shell on your system. There is one other way to test this. Type this into your terminal.
If you have csh installed on your system you will see something similar to this.
PID TTY TIME CMD 13964 pts/0 00:00:00 bash 22450 pts/0 00:00:00 csh 22451 pts/0 00:00:00 ps
If you don’t have csh installed on your system then install it will this command.
Why change your shell
The UNIX shell is most people’s main access to the UNIX operating system and as such any improvement to it can result in considerably more effective use of the system, and may even allow you to do things you couldn’t do before. The primary improvement most of the new generation shells give you is increased speed. They require fewer key strokes to get the same results due to their completion features, they give you more information (e.g. showing your directory in your prompt, showing which files it would complete) and they cover some of the more annoying features of UNIX, such as not going back up symbolic links to directories.
Deciding on a shell
Which of the many shells you choose depends on many different things, here is what I consider to be the most important, you may think differently.
- There is no point in using a shell with a different syntax, or a completly different alias system if you havn’t the time to learn it. If you have the time and are presently using csh or tcsh it is worth considering a switch to a Bourne shell variant.
- The main reason for switching shells is to gain extra functionality; its vital you know what you are gaining from the switch.
- If you may have to switch back to a standard shell, it is fairly important you don’t become too dependent on extra features and so can’t use an older shell.
- The more advanced shells tend to take up extra CPU, since they work in cbreak mode; if you are on an overloaded machine they should probably be avoided; this can also cause problems with an overloaded network. This only really applies to very old systems nowadays.
- If your new shell is not supported make sure you have someone you can ask if you encounter problems or that you have the time to sort them out yourself.
- Switching between certain shells of the same syntax is alot easier than switching between shells of a different syntax. So if you havn’t much time a simple upgrade (eg csh to tcsh) may be a good idea.
- Like most software all shells have some bugs in them (especially csh), can you afford the problems that may occur because of them.
How to Change Shells
- Temporarily changing your shell for the session you are in.
- Changing your login shell which is permanent.
Temporarily changing your shell for the session you are in
I will use csh as again an example. I will assume you already have csh installed on your system. All you need to do is type the command below into your terminal.
There are a few ways to verify this. This first comes from above.
If you have csh installed on your system you will see something similar to this.
PID TTY TIME CMD 13964 pts/0 00:00:00 bash 22450 pts/0 00:00:00 csh 22451 pts/0 00:00:00 ps
The second: Upon changing shells, a different command prompt (i.e., the short text message at the left of each command line) may be shown, depending on the previous and new shells. For example, if the original shell were bash and the new shell is sh, the command prompt would change for a user george from something like [george@localhost george]$ to something like sh-2.05b$.
To return to the original shell, or any other one for that matter, all that is necessary is to just type its name and then press the ENTER key. Thus, for example, to return to the bash shell from the sh shell (or from any other shell), all that is required is to type the word bash or exit.
Changing your login shell which is permanent
You will use a program called chsh. There is a interactive method and non-interactive method. Type this into your terminal.
interactive method
This results in a brief dialog in which the user is prompted first for its password and then for the full path of the desired new shell.
Caution should be exercised when changing one’s default shell because it is possible to make an error that only the root user (i.e., system administrator) can repair (although it should be easy for a skilled user to repair it on a home system). In particular, it is important to first test the shell temporarily in the current session and then to make certain that a valid shell name is being entered when making the permanent change.
non-interactive method
I will use csh as again an example.
The -s sets it for you without having to go into the editor to do it.
Okay you did the command and it went ok.but the echo says it is the same. Log out and back it for the change to take effect.Then do echo $SHELL. You should see it show the new shell.
More information
If you would like more information I recommend reading these websites.
ChangingShells (последним исправлял пользователь 63-144-199-3 2010-12-02 10:49:22)
The material on this wiki is available under a free license, see Copyright / License for details.
3 Ways to Change a Users Default Shell in Linux
In this article, we will describe how to change a user’s shell in Linux. The shell is a program that accepts and interprets commands; there are several shells such as bash, sh, ksh, zsh, fish and many other lesser known shells available on Linux.
Bash (/bin/bash) is a popular shell on most if not all Linux systems, and it’s normally the default shell for user accounts.
There are several reasons for changing a user’s shell in Linux including the following:
- To block or disable normal user logins in Linux using a nologin shell.
- Use a shell wrapper script or program to login user commands before they are sent to a shell for execution. Here, you specify the shell wrapper as a user’s login shell.
- To meet a user’s demands (wants to use a specific shell), especially those with administrative rights.
When creating user accounts with the useradd or adduser utilities, the —shell flag can be used to specify the name of a user’s login shell other than that specified in the respective configuration files.
A login shell can be accessed from a text based interface or via a SSH from remote Linux machine. However, if you login via a graphical user interface (GUI), you can access the shell from a terminal emulators like xterm, konsole and many more.
Let’s first list all available shells on your Linux system, type.
# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/tcsh /bin/csh /bin/dash
Before you proceed any further, note that:
- A user can change their own shell to any thing: which, however must be listed in the /etc/shells file.
- Only root can run a shell not listed in /etc/shells file.
- If an account has a restricted login shell, then only root can change that user’s shell.
Now let’s discuss three different ways to change Linux user shell.
1. usermod Utility
usermod is a utility for modifying a user’s account details, stored in the /etc/passwd file and the -s or —shell option is used to change the user’s login shell.
In this example, we’ll first check user tecmint’s account information to view his default login shell and then change its login shell from /bin/sh to /bin/bash as follows.
# grep tecmint /etc/passwd # usermod --shell /bin/bash tecmint # grep tecmint /etc/passwd
2. chsh Utility
chsh is a command line utility for changing a login shell with the -s or –shell option like this.
# grep tecmint /etc/passwd # chsh --shell /bin/sh tecmint # grep tecmint /etc/passwd
The two methods above all modify the shell specified in /etc/passwd file which you can edit manually as in the third method below.
3. Change User Shell in /etc/passwd File
In this method, simply open the /etc/passwd file using any of your favorite command line text editors and change a specific users shell.
When your done editing, save and close the file.
Do not forget to read these related topics:
In this article, we described various ways of changing a user’s shell in Linux. To share any thoughts with us, use the comment section below.
What is default shell for terminal?
Let’s say, I opened a terminal and entered / executed some shell commands. But I didn’t invoke explicitly Bash or any other shell. What shell was used by default?
5 Answers 5
The one specified on your line in /etc/passwd (it is a : separated line and the shell is the final one).
chris:x:1000:1000:Chris. /home/chris:/bin/bash
Here it is /bin/bash (the Ubuntu default)
$ chsh Password: Changing the login shell for chris Enter the new value, or press ENTER for the default Login Shell [/bin/bash]:
This is telling me my shell is /bin/bash and letting me change it.
Finally, echo $SHELL will do the same:
if it’s bash, why is it sometimes invoked explicitly like sudo bash -c «netstat -an | grep LISTEN | grep -v ^unix» ??
I think that’s a bad command personally — none of that even requires root. If it did, it would be better written as sudo netstat -an | grep LISTEN | grep -v ^unix . I see no reason to enclose that in a bash subshell.
@DrStrangeLove: If more than one command in the pipe needed root permissions, then sudo bash -c «. » would ensure that the entire pipe is executed by root.
If you don’t know which commands require root (and why), you shouldn’t run them. Otherwise, why trust any command/program/script any more than is required. If you can’t commandA | sudo commandB | commandC , you could do a sudo id first (runs the id command as root , but also acquires a «use sudo without password prompt» token that lasts for (default) 15 minutes.