Linux changing default shell

Change my default shell in Linux using chsh

How to Change my default shell

  1. First, find out the available shells on your Linux box, run cat /etc/shells
  2. Type chsh and press Enter key
  3. You need to enter the new shell full path. For example, /bin/ksh
  4. 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 «^$» /etc/passwd

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 «^$» /etc/passwd
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

Источник

how to change the default shell of an user in linux?

There are several different command shells available to you in Linux. bash, csh, tcsh, ksh, zsh, sh and fish are just a few of the popular ones that can be used by an user from the command line. As a system administrator, you can specify a default shell for the user. The user can however choose the run another shell of his choice later by overriding the default shell.

For this post, we will assume that your current default shell is csh and you want to change it to bash. The steps will however work just the same for any shell that you want to change to.

First thing to do is to make sure that you have the required shell installed, in this case the bash shell. You need to find the path to the shell executable or where the shell is installed. The shells are usually installed in the /bin/ folder unless you have a distro which installs in other locations such /usr/bin/ or /usr/local/bin/.

find location of the shell

You can find where the shell is installed by using either which or whereis command. The which command will show you exactly where in the path the shell executable is.

Читайте также:  Linux screen list all screens

If which cannot find the shell you want to change to, and you are sure that it is installed then you might want to double check the environment path and make sure that the installed folder is in the path. The location of the shell executable is all you need to change the default shell.

Unlike the which command, the whereis command will show you the location of the binary/executable, source and documentation of the command. The first path in the output is the location of the shell binary.

You can see the list all the shells that are installed on your system in the /etc/shells file. Use the cat command to print out the contents of this file. It lists the binary file location of the installed shells. You can change to any of the shell listed here.

change the default shell

Once you have the location of the new shell, you can change the default for any user as long as you have the root or super user credentials. You can use either the usermod or the chsh command to do it. You can also do it manually by editing the passwd file.

$ usermod -s /bin/bash

usermod is the command used to modify user accounts. The -s or –shell option is used specify the default shell for the user. Substitute in the above example with the actual username of the user.

Another command you can use is chsh. It changes the login shell or the default command shell for any user. The syntax of this command is just about the same as the usermod command above.

The -s or –shell option is for the path of the new shell followed by the actual username for the user.

You can also change the shell directly in the /etc/passwd file. This is probably more riskier than using the commands above. The default shell of the user is the last field on the line where the user is listed. Use your favorite text editor to open the /etc/passwd file and search and find the user name in the file. You will see something like this :

Now change the “/bin/csh” part of the line to “/bin/bash” and save the file. The modified line will look like this:

change shell at time of use

If you do not have root access or the permission to modify the /etc/passwd file, then you are left with the option of executing the shell after you have logged in. This does not change the default shell but still allows you use the shell of your choice.

First, you need to find the location of the shell as described above. Now, find the file that configures your current shell. You will see that there are several files that fits, such as .profile, .bashrc, .bash_profile, .login etc etc. The differences between these files are beyond the scope of this post.

I recommend that you use the rc file, for example .bashrc or .cshrc. The reason for using it is that it is read by the interactive, login and non-login prompts. You can use any of the configuration files depending on your requirements.

So, if your default shell is csh then open the .cshrc file in your favorite text editor and add the following to it…

setenv SHELL /bin/bash
exec /bin/bash —login

If your current default shell is something other than csh, then you will use the corresponding file. You can just use the .login or .profile as well, which are usually read by most shells. Be sure to use the correct syntax for setting the environment variable SHELL for the shell.

Also, you will need to add any personalization and shell specific configuration in the config file of the new executing shell. That means you can set aliases and prompt format etc in the .bashrc file once you have changed to the bash shell.

Источник

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.

Читайте также:  Windows system32 svchost exe trojan

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.).

Читайте также:  Windows explorer plus sign

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.

Источник

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:

  1. To block or disable normal user logins in Linux using a nologin shell.
  2. 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.
  3. 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.

Источник

Оцените статью