- Change my default shell in Linux using chsh
- How to Change my default shell
- List your shells in Linux
- Find out your current shell name
- Changing default shell from bash to ksh
- Changing back your shell to bash with chsh
- Getting help about the chsh command
- Conclusion
- 3 Ways to Change a Users Default Shell in Linux
- 1. usermod Utility
- 2. chsh Utility
- 3. Change User Shell in /etc/passwd File
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How To Change The Default Shell In Linux
- How to change the default login shell using chsh (from the command line)
- Change the shell for your user in a terminal application
- How to Change Shell in Linux
- How to know the default shell?
- How to see what shell are you currently using?
- How to see all the shells available on your Linux system?
- How to change the shell to use another one?
- How to change the default shell in Linux permanently?
Change my default shell in Linux using chsh
How to Change my default shell
- First, find out the available shells on your Linux box, run cat /etc/shells
- Type chsh and press Enter key
- You need to enter the new shell full path. For example, /bin/ksh
- Log in and log out to verify that your shell changed corretly on Linux operating systems.
Let us see all commands in details.
List your shells in Linux
Run the following cat command on the /etc/shells file:
cat /etc/shells
Of course, we can use the grep command/egrep command to find out if particular shell such as zsh or fish installed or not, run:
grep «zsh» /etc/shells
grep «fish» /etc/shells
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Find out your current shell name
Execute any one of the following command to find the current shell instance:
ps -p $$
OR
printf «My current shell — %s\n» «$SHELL»
OR
grep «^$
Changing default shell from bash to ksh
To change your shell to zsh with chsh, run:
type -a zsh ## find path to ksh ##
chsh -s /bin/zsh ## change bash to ksh ##
Verify it:
grep «^$
Log out and log in again. One can close the Terminal app and reopen it or use the su command as follows”
su — vivek
Changing back your shell to bash with chsh
Want to reverse changes? Try:
type -a bash
chsh -s /bin/bash
## replace vivek with actual username ##
grep ‘^vivek’ /etc/passwd
su — vivek
Getting help about the chsh command
Type any one of the following command at the CLI:
man chsh
OR
chsh —help
The options are as follows:
- -h : Display help message and exit.
- -R CHROOT_DIR : Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.
- -s /path/to/SHELL : The name of the user’s new login shell. Setting this field to blank causes the system to select the default login shell.
Conclusion
You learned about changing your default shell with chsh command. See shadow-utils home page for more info here.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
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.
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.
Change User Shell using Usermod
2. chsh Utility
chsh is a command line utility for changing a login shell with the -s or –shell option like this.
Change User Shell Using chsh
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.
Change User Shell in Passwd File
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.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How To Change The Default Shell In Linux
This article explains how to change the default shell in Linux. Using this you can set Bash, sh, Zsh, Csh, Fish, etc. as your shell.
The article includes instructions for changing the login shell from the command line using chsh, or changing the shell only for a particular terminal application. While the article is targeted at Linux users, this should also work on other Unix-like systems.
How to change the default login shell using chsh (from the command line)
To change the default login shell we’ll use chsh , a command line tool to change the login shell.
This program changes the login shell by modifying the /etc/passwd file and setting the $SHELL environment variable. You can override the default shell in a terminal application, by setting the shell from the terminal settings — see the second part of this article for details.
A note for Fedora users. Fedora doesn’t have chsh installed by default and to use it, you must install a package called util-linux-user . If you want to skip installing this package, you can use lchsh instead to change the login shell, which is available by default:
It’s important to note that using chsh, a normal user may only change the login shell for the current account, while the superuser may change the login shell for any account, including the root account. Also, the default behavior for non-root users is to accept only shells listed in the /etc/shells file, and issue a warning for root user.
So before changing your shell, list all the shells listed in the /etc/shells file from your Linux system by using the following command:
Example with output:
If the shell you want to use is not listed here, it may not be installed on your system. So install it (for example, install Zsh on Debian / Ubuntu / Linux Mint / Pop!_OS using: sudo apt install zsh ) and check again.
To change the shell for your user, run:
This runs chsh in an interactive mode, asking you for the password, then listing your current shell (most Linux distributions use Bash as the default shell) and asking you to enter a value for your new shell. Here’s the command with its output:
To change your shell, type the path to the new shell (which exists in /etc/shells ) and press the Enter key.
For example, to change the shell for the current user from Bash to Zsh:
In case you’re using a chsh version that doesn’t launch with an interactive prompt after executing chsh , change the login shell for your user directly:
E.g. to change the shell to Zsh:
After changing your account’s shell, logout and re-login to use the new shell.
To change the login shell for another user or for the root user, login to the shell prompt as root using su — , sudo -i , sudo su , etc., and run:
- To change the shell for the root account (and when prompted, enter the login shell you want to use, with its full path):
- To change the shell of another user (this also works for the root user, using root as the username):
This time we’ve used chsh with the -s option, which changes the login shell directly (doesn’t run in an interactive mode). Here, SHELL is the new shell (e.g. /bin/zsh ) and USERNAME is the user for which you’re changing the shell; for example, to change the shell to /bin/zsh for the user Logix , you’d use: chsh -s /bin/zsh Logix ).
Change the shell for your user in a terminal application
You can use a shell that’s different from the login shell ( $SHELL ) for a particular terminal application, if that application allows setting a custom shell or running a custom command instead of the default shell.
As a side note, you may also change the current shell (non-permanent change) by typing the shell command you want to use in a terminal (e.g. if you type «zsh», you’ll switch to using Zsh for that session; exit by typing «exit».).
Take GNOME Terminal for example (used in GNOME and Cinnamon desktops as the default terminal). Open its Preferences , click on the current active profile (usually called Default or Unnamed if you haven’t changed it or added new profiles) in the left-hand sidebar, then click on the Command tab:
This is where you can set a custom shell to be used with this application only. Enable the Run a custom command instead of my shell option, then in the Custom command field enter the full path to the shell you want to use, e.g. /bin/zsh , /bin/bash , etc.
In Xfce4 Terminal, open the Preferences and on the General tab you’ll need to enable an option called Run a custom command instead of my shell , then enter the custom command below that (this being the shell you want to use with this terminal, e.g. /bin/zsh , /usr/bin/fish , etc.).
Using KDE Plasma’s Konsole, go to Settings -> Edit Current Profile , and on the General tab, change the Command field to the full path of the shell you want to use (once again, something like: /bin/zsh , /bin/bash , /usr/bin/fish , etc.).
Using Guake, you can change the user shell from its Preferences , on the Shell tab, where you’ll find an option called Default interpreter that allows choosing any shell listed in /etc/shells .
For terminals that allow running a custom shell you should also find an option that allows running the command as a login shell (usually called just that: «Run command as a login shell»). To read on the differences between a login shell and an interactive shell, see this page.
Setting this is the same in most cases, so I won’t give any more examples. However, it’s worth noting that not all terminal applications have options to allow using a custom shell — in such cases, use the chsh command to change the login shell, as explained above.
Источник
How to Change Shell in Linux
This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.
You probably are already aware that there are several shell available on Linux and other Unix-like systems. Bash is the default shell on almost all the Linux distributions but there are some other popular shells available such as:
Some of the shells provide additional features in a more user-friendly way. Take Fish shell for example. It partially starts showing you command hints based on your previous typed command. It’s quite handy if you don’t want remember the Linux terminal shortcuts all the time.
Let’s see a few things around shell in your Linux system.
How to know the default shell?
To know the default shell set for you in your Linux system, you can check the SHELL environment variable. Usually, the default shell is bash and it is shown like this:
How to see what shell are you currently using?
There is no single method that will tell you which shell you are using with 100% accuracy.
You can try either echo $0 that shows you an output like this:
or check the process using ps -p $$ like this:
How to see all the shells available on your Linux system?
All the shells available on your Linux systems are listed in the file /etc/shells. You can use cat command or less command to view the content of the file.
How to change the shell to use another one?
If you want to use a different shell, you can simply type its name and you’ll be logged into the new shell. For example, if you install zsh and want to use it, you can simply use:
You can enter exit to exit from the new shell and return to the previous one.
How to change the default shell in Linux permanently?
Suppose you liked the Fish shell a lot and you want to use it as your default shell so that every time you open the terminal or ssh into the system, you are using it instead of the default bash shell.
Linux allows you to change the default shell using the chsh command. The best way to change the default shell for your own logged in user is by specifying the shell name listed in the /etc/shells file with the -s option.
You must log out of the system so that the changes take into effect otherwise you’ll think that running chsh didn’t change the shell.
Did you notice that I had to specify the full path as it was listed in the /etc/shells file? If I had used chsh -s fish, it would have given me an error like “chsh: fish is an invalid shell”.
Which shell do you like?
Now that you know how to change shell, you may also read how to change users in Linux.
I hope this little article helped you to change the shell in Linux. If you have thought about changing the default shell, perhaps you use something other than the bash shell. Which shell is it? Why do you prefer it over the others?
Источник