Linux user 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.

Читайте также:  Урок знакомство с windows

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.

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.

Читайте также:  Install flutter on linux

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.

Источник

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.

Читайте также:  Samsung scx 3400f драйвер windows 10

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 Default Shell In Linux

In most Linux systems, the default shell is bash but we can change that to any other shell-like zsh, fish, sh, and any other. In this article, we are going to show how to change that default shell to any other shell in Linux systems. To change the user’s shell, first, let’s find the current shell. There are many ways by which we can change the shell of any user on a Linux system. We are going to see three methods of changing the user’s shell.

Find your current shell name

In Linux systems, there is one file which is /etc/passwd. The /etc/passwd file stores essential information of user accounts, which is required during login. By using this file we can identify the current user login shell.

We are going to see the current user information in the /etc/file using the following command:

In the above image we can see that the user nishant (current user) has home directory /home/nishant and the shell is /bin/sh

List your shells in Linux

Now to change the shell, first, we need to see which shells are installed on the system. We can check installed shells using the following command :

This will show all shells as follows:

Before moving further, first understand who can change the user shell

  • Users can change shell to any other shell listed in /etc/shells/.
  • The root account can be used to change any other user login shell.
  • If an account has a restricted login shell, then only the root can change that user’s shell.

Changing default sh shell to bash

Using usermod command

usermod is a command that modifies the system account files. usemod can change the shell of Users by modifying file /etc/passwd. usermod command provides the -s or –shell option to change the user’s login shell.

In this example, we are going to change the shell of a user named nishant. We are going to change the shell from /bin/sh to /bin/bash of user nishant using usermod command.

With usermod command mention shell and usernmae after –shell option.

Now you can see the shell use changed. In the above commands, replace nishant with the user name whose shell has to change.

Using chsh Utility

chsh is the utility to change a user’s login shell. chsh provides the -s option to change the user’s shell. This method also modifies the file /etc/passwd. Use the following command to change shells using chsh:

Change User Shell to /etc/passwd File

As we see in the above two methods, the usermod command and chsh utility modify the /etc/passwd file and change the user shell. We can do that manually also by editing the /etc/passwd file. Just change the shell after the username and home directory in the /etc/passwd file and save the file.

Источник

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