How do you change the default shell for ALL USERS to bash?
Solution 1
adduser
The adduser
defaults file is /etc/adduser.conf
. The default shell defined by the DSHELL
variable is /bin/bash
by default.
useradd
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
- login name
- optional encrypted password
- numerical user ID
- numerical group ID
- user name or comment field
- user home directory
- optional user command interpreter
In that order separated by colons (:) like this.
root:x:0:0:root:/root:/bin/bash
For more information about that file consult the man page man 5 passwd
.
Solution 2
As Octavian pointed out, the way to change the defaults depends on the way you're creating the user. I tried creating a new user through my Gnome Settings just now, and it seems to follow /etc/default/useradd
, so that might be your best bet. For existing users, the safest way to change someone else's login shell is with usermod:
usermod -s /bin/bash $USERNAME
If you're not root, you'll need to sudo that. An alternative is to sudo into the user you want to modify and just run chsh, like this:
sudo -u $USERNAME chsh -s /bin/bash
It's best to avoid editing /etc/passwd
by hand, because a mistake in there could break all sorts of things.
Solution 3
If you actually want all users on the server to have bash (which was the question actually asked), you can run the command:
sudo dpkg-reconfigure dash
And then choose NOT dash. As explained in this answer,
How Can I Make /bin/sh point to /bin/bash?
Not only does that set bash as the default shell, but repoints sh and the man pages correctly.
Hope this helps.
Related videos on Youtube
Comments
-
coffee-grinder over 1 year
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?
-
Jack O'Connor over 10 yearsI think a safer way to change another user's shell would be something like
sudo -u $USER chsh -s $SHELL
. -
Octavian A. Damiean over 10 years@JackO'Connor you should post that as an answer as well.
-
Harshdeep almost 7 yearsThis does not seem to be working in Ubuntu 16.04. Does anyone know the fix.