Setting default shell in linux

How do I make Bash my default shell on Ubuntu?

I have a .bash_profile in my home directory, but it isn’t getting run on login. If I do the following, then things seem to be as I expect:

ssh myhost bash source ~/.bash_profile 

Also make sure that you don’t have a ~/.profile or ~/.bash_login , as only one of the three is sourced. (I forgot the exact order.)

9 Answers 9

Enter your password and state the path to the shell you want to use.

For Bash that would be /bin/bash . For Zsh that would be /usr/bin/zsh .

+1 — not sure why the OP decided that editing the password file was a better choice, but this is the best answer

On top of akira’s answer, you can also edit your /etc/passwd file to specify your default shell.

You will find a line like this example:

john:x:1000:1000:john. /home/john:/bin/sh 

The shell is specified at the end.

Better to use the ‘chsh’ command as suggested by akira — less chance to screw something up by mistake.

But if you so have access to modifying the /etc/passwd and you’re careful, John’s answer is making good use of the tools the system provides.

If you’re running a server without user passwords — providing access only through public/private ssh keys . it also makes a lot of sense. chsh requires a password.

$ sudo usermod -s /bin/bash username 
 -s, --shell SHELL new login shell for the user account 

(1) What do you mean by “enable bash”? (2) The user wants to change his own login shell on a remote system. Why do you assume that he has sudo access on that system? Why do you provide instructions in terms of changing another user’s login shell?

You might check your terminal program. It might be configured to run /bin/sh rather than /bin/bash

Bash executes .bash_profile only for login sessions. .bashrc is executed for all bash sessions, not only login sessions. Try sourcing .bash_profile from .bashrc (avoid circular dependency!) or configuring your terminal program to run /bin/bash -l as a shell program.

terminal program has nothing to do with the problem because it is the sshd on the remote machine, which spawns the new shell.

To make any shell your default, first verify it is installed and recognized on your computer by looking at the contents of /etc/shells :

$ cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/bash /usr/bin/bash /bin/rbash /usr/bin/rbash /bin/dash /usr/bin/dash /usr/bin/fish 

Then use chsh to change your shell:

$ sudo chsh -s /usr/bin/bash $(whoami) # or sudo chsh -s /bin/bash $(whoami) 

References

If you somehow don’t see your username in the /etc/passwd file [this is the case when your system is under control of some other domain e.g. in IT companies] Or it says «user not found» with chsh option than below process might help you.

Читайте также:  Kali linux root commands

The logic behind the below trick -> On Ubuntu, /bin/sh is dash. You can switch your system to using bash. On Ubuntu, /bin/sh is a symbolic link to dash. You can make it a symbolic link to bash instead.To change it, run

sudo dpkg-reconfigure dash

And press No to switch to bash.

Now, go to Terminal->Edit->preferences->Command and tick the checkbox with statement

One alternative is to rename your startup script into .profile. This file is being source by most Unix shells.

There’s not enough information in your question for me to say for sure, but I’ve hit the same problem before. Assuming you’ve already get /bin/bash set in your password entry, it may be the way your terminal launches.

If you’re trying to launch a GUI terminal, say gnome-terminal you may be expecting the shell to read your bash startup files. However, this doesn’t happen on Ubuntu and maybe other systems by default.

The way I’ve fixed it on Ubuntu is to edit the gnome-terminal preferences, and set the startup command to be bash -l . -l is short for —login . This tells bash to startup as as login shell, which causes it to load the startup scripts as you get when logging in via ssh.

I’m sure there’s a good rationale for this being the way it is, but I found it surprising and a more than a bit annoying as I share the same profiles across linux, cywgin and macos systems.

Источник

How To Change The Default Shell In Linux (Bash, Zsh, Fish, Etc.)

change default shell 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:

$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/bin/rbash
/bin/dash
/usr/bin/tmux
/bin/zsh

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:

$ chsh
Password:
Changing the login shell for logix
Enter the new value, or press ENTER for the default
Login Shell [/bin/bash]:

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:

$ chsh
Password:
Changing the login shell for logix
Enter the new value, or press ENTER for the default
Login Shell [/bin/bash]: /bin/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:

Читайте также:  Seeing linux files from windows

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 do you change the default shell for ALL USERS to bash?

I want every new user from now on to have bash as their shell by default. I know that to change your own shell to bash, you would use the command «chsh -s /bin/bash», but how do I automatically set all future users’ shell to bash by default?

3 Answers 3

The adduser defaults file is /etc/adduser.conf . The default shell defined by the DSHELL variable is /bin/bash by default.

Most likely you don’t need this because useradd is a very low-level utility, and it’s hardly ever used directly.

If you use useradd, edit the /etc/default/useradd skeleton file (don’t forget to make a backup though).

Set the SHELL variable to /bin/bash instead of /bin/sh .

Now every time you use useradd to add a new user bash is automatically their default shell.

Already existing users

If you want to change the shell of already existing users you have to edit the /etc/passwd file (please make sure to back have a backup of it).

Here is a description of the columns

  1. login name
  2. optional encrypted password
  3. numerical user ID
  4. numerical group ID
  5. user name or comment field
  6. user home directory
  7. optional user command interpreter

In that order separated by colons (:) like this.

For more information about that file consult the man page man 5 passwd .

Источник

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