Shell management: Difference between revisions

From Alpine Linux
m (Prabuanand moved page Change default shell to Shell management: to add more information on default shell and other available shells)
(changed headings, moved content from BusyBox page)
Line 1: Line 1:
Alpine Linux uses the [[BusyBox]] variant of the [[BusyBox#Ash_shell|ash]] shell. This page explains various ways to change the default shell in Alpine Linux to other popular shells like {{Pkg|bash}}, {{Pkg|zsh}}, {{Pkg|fish}} etc.. You can revert back to '''ash shell''' at anytime with the same steps.
The default shell used by Alpine Linux is the [[BusyBox]] variant of the [[BusyBox#Ash_shell|ash]] shell. This page explains how to use the default shell and various ways to change the default shell in Alpine Linux.
 
== Ash shell ==
 
Alpine Linux uses [[Busybox]] Ash shell for its default shell. It a standard POSIX shell and its syntax is comparable to bash; one's ~/.bashrc file (or, alternatively, a different shell alias file) could be considered as a basis, say, for an ~/.ashrc file, reviewing it carefully for syntax/cli variants against that of busybox, and configured to be sourced for busybox shells.
 
=== Setting alias ===
 
When using Ash shell, one can’t set aliases in the {{Path|~/.profile}}, but environment variables can be set in it. In order to use aliases with Busybox Ash, you must set the ENV environment variable to refer the aliases file.
 
First create the file {{Path|/etc/profile.d/profile.sh}} as follows:
{{Cat|/etc/profile.d/profile.sh|if [ -f "$HOME/.config/ash/profile" ]; then
. "$HOME/.config/ash/profile"
fi
}}
Next create the file {{path|~/.config/ash/profile}} as follows:
{{Cat|~/.config/ash/profile|export ENV{{=}}"$HOME/.config/ash/ashrc"
}}
Now aliases can be added in the file {{Path|~/.config/ash/ashrc}}:
 
{{Cat|~/.config/ash/ashrc|su{{=}}"doas -s"
}}
 
== Available shells ==
 
All popular shells are available in Alpine Linux. Refer to the following list:
 
* {{Pkg|bash}}
* {{Pkg|zsh}}  
* {{Pkg|fish}}  
 
== Change default shell ==
 
There are various ways to change the default shell in Alpine Linux. You can revert back to [[#ash|ash]] shell at anytime with the same steps.  


{{Note|You need to log out and login again for these changes to take effect.}}
{{Note|You need to log out and login again for these changes to take effect.}}


== By hand ==
=== By hand ===
Edit {{Path|/etc/passwd}} manually. An example line for a user named <code>user</code> is:


{{Cat|/etc/passwd|...
Edit {{Path|/etc/passwd}} manually using an editor of your choice. An example line for a user named <code>user</code> is: {{Cat|/etc/passwd|...
user:x:1000:1000:user:/home/user:/bin/ash
user:x:1000:1000:user:/home/user:/bin/ash
...
...
Line 13: Line 45:
Change {{Path|/bin/ash}} to point to the path of a shell from {{Path|/etc/shells}}. Take care to not delete/mangle the line, as it would make you unable to log in again. The <code>user</code> should be the user you are changing the default login shell for.
Change {{Path|/bin/ash}} to point to the path of a shell from {{Path|/etc/shells}}. Take care to not delete/mangle the line, as it would make you unable to log in again. The <code>user</code> should be the user you are changing the default login shell for.


== Using shadow ==
=== Using chsh command ===
 
Download the required package:
{{Cmd|# apk add shadow}}
And use chsh:
{{Cmd|# chsh username}}


To use {{ic|chsh}} command, install the {{pkg|shadow}} package: {{Cmd|# apk add shadow}}
And use chsh: {{Cmd|# chsh username}}
Now enter the path for the shell you want to use (e.g {{Path|/bin/zsh}})
Now enter the path for the shell you want to use (e.g {{Path|/bin/zsh}})
and press {{Key|Enter}} to confirm this change. The shell should exist in {{Path|/etc/shells}}.
and press {{Key|Enter}} to confirm this change. The shell should exist in {{Path|/etc/shells}}.

Revision as of 04:03, 20 July 2025

The default shell used by Alpine Linux is the BusyBox variant of the ash shell. This page explains how to use the default shell and various ways to change the default shell in Alpine Linux.

Ash shell

Alpine Linux uses Busybox Ash shell for its default shell. It a standard POSIX shell and its syntax is comparable to bash; one's ~/.bashrc file (or, alternatively, a different shell alias file) could be considered as a basis, say, for an ~/.ashrc file, reviewing it carefully for syntax/cli variants against that of busybox, and configured to be sourced for busybox shells.

Setting alias

When using Ash shell, one can’t set aliases in the ~/.profile, but environment variables can be set in it. In order to use aliases with Busybox Ash, you must set the ENV environment variable to refer the aliases file.

First create the file /etc/profile.d/profile.sh as follows:

Contents of /etc/profile.d/profile.sh

if [ -f "$HOME/.config/ash/profile" ]; then . "$HOME/.config/ash/profile" fi

Next create the file ~/.config/ash/profile as follows:

Contents of ~/.config/ash/profile

export ENV="$HOME/.config/ash/ashrc"

Now aliases can be added in the file ~/.config/ash/ashrc:

Contents of ~/.config/ash/ashrc

su="doas -s"

Available shells

All popular shells are available in Alpine Linux. Refer to the following list:

Change default shell

There are various ways to change the default shell in Alpine Linux. You can revert back to ash shell at anytime with the same steps.

Note: You need to log out and login again for these changes to take effect.

By hand

Edit /etc/passwd manually using an editor of your choice. An example line for a user named user is:

Contents of /etc/passwd

... user:x:1000:1000:user:/home/user:/bin/ash ...

Change /bin/ash to point to the path of a shell from /etc/shells. Take care to not delete/mangle the line, as it would make you unable to log in again. The user should be the user you are changing the default login shell for.

Using chsh command

To use chsh command, install the shadow package:

# apk add shadow

And use chsh:

# chsh username

Now enter the path for the shell you want to use (e.g /bin/zsh) and press Enter to confirm this change. The shell should exist in /etc/shells.