Linux changing the shell

Howto: Changing Linux Login Shell

chsh command syntax

Following is syntax for chsh command:
chsh -s
Where,

  • -s : Specify your login shell name. You can obtained list of avialble shell from /etc/shells file.
  • User-name : It is optional, useful if you are a root user.

First, find out available shell list:
$ less /etc/shells
Sample Outputs:

Example: Changing default shell in Linux to /bin/tcsh

To change your shell name to /bin/tcsh:
$ chsh -s /bin/tcsh
Sample outputs:

When promoted for password, type your own password. You must log out and log back in to see this change. If you just type chsh command, it will prompt for shell name interactively:
$ chsh
Sample outputs:

This command will change the default login shell to /bin/tcsh permanently. In this example, first find out path for bash shell, enter:
$ type -s bash
$ which bash
Sample outputs:

  • 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

Now use the below command to set shell to bash for a user named vivek:
$ chsh -s /usr/local/bin/bash vivek
OR if you know sysadmin root passoword:
$ sudo chsh -s /usr/local/bin/bash vivek

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

How To Change Shell To Bash in Linux / Unix

H ow do I switch from a ksh shell to bash on Linux or Unix system? How to change shells on Unix-like system?

A shell is nothing but a command that provides a text-only user interface (also known as “command line interface”) for Linux, MacOS, and Unix-like operating systems. Bash shell read commands such as ls, date and others typed into a terminal and then run them. That is the primary function of bash shell.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix-like OS
Est. reading time 2 minutes

How do I find out the default shell for a user?

Type the following command to find out the default shell for a user named vivek using the grep command and /etc/passwd file:
$ grep vivek /etc/passwd
vivek:x:1005:1005. /home/vivek: /bin/zsh
OR
$ ps -p $$
PID TTY TIME CMD
14314 pts/9 00:00:00 zsh

OR
$ echo $0
zsh
All of the above output indicates that the shell is zsh for user named vivek in Linux operating system.

How do I see what shells are available on my system?

Type the cat command as follows:
$ cat /etc/shells

Fig.01: How to find list of available shells on Linux or Unix or MacOS?

How do I switch to a bash or different shell?

Type the name at the command line and then press the enter key. In this example, to change from any shell to the bash, type:
bash

  • 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

How to change shells on a Linux or Unix-like systems?

You can change your default shell using the chsh (“change shell” ) command as follows. The syntax is:
chsh
chsh -s
chsh -s
chsh -s /bin/bash
chsh -s /bin/bash vivek
You can find full path to your shell using the following command:
type -a bash
type -a zsh
type -a ksh
Please note that a normal user may only change the login shell for her own account. The superuser (root) may change the login shell for any account using the following syntax:
$ sudo chsh -s /bin/bash raj
OR use the su command instead of sudo command:
$ su —
# chsh -s /bin/bash monika

Summing up

The only restriction placed on the login shell is that the shell command name must be listed in /etc/shells file, unless the invoker is the superuser/root user, and then any value may be added. An account with a restricted login shell may not change her login shell. For this reason, placing /bin/rsh in /etc/shells is discouraged since accidentally changing to a restricted shell would prevent the user from ever changing her login shell back to its original value.

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

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.

Источник

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.

Источник

Читайте также:  Ios приложения с windows phone интерфейсом
Оцените статью