Set Default Shell in Cygwin

There's an answer on SuperUser that is even simpler. Set the SHELL environment variable in Windows. Set it to your preferred shell (e.g. /bin/tcsh) and newly-launched shells should use it.

To set environment variables:

  1. Go to the "System" control panel (right-click on the Start menu and select "System")
  2. Click on "Advanced system settings" in the left-side column
  3. From the "System Properties" window that pops up, click the "Environment Variables..." button
  4. In either the "User variables" or "System variables" box (depending on whether you want the change to affect just yourself or all users), click the "New..." button.
  5. Type "SHELL" in the "Variable name" box and the path (relative to the Cygwin file system) to your preferred shell in the "Variable value" box.
  6. Click OK on the three open windows to save your changes.

I randomly meet the same problem, and now I providing my solution for you.

0- Open cygwin by mintty.exe

1- Build passwd file manually (mkpasswd)

$mkpasswd > /etc/passwd

2- Change default shell in passwd file

$vim /etc/passwd
user:*:1976XX:1971XX:U-user\user,S-1-5-21-XXXX:/home/user:/bin/fish

3- Restart mintty.exe


I'm not sure how 'proper' of a solution this is, but I just added /usr/bin/zsh; exit to the bottom of my .bashrc file. You can substitute /usr/bin/zsh for the path to your shell of choice. It seems to work just fine so far.


Try editing /etc/nsswitch.conf instead of /etc/passwd

Instead of creating a passwd file, which Cygwin recommends against1, you could edit /etc/nsswitch.conf. Add or edit the following line:

db_shell: /usr/bin/fish

The down/up side of this method is that, if you have multiple users, this change affects all of them. The up/up side is that it's dead simple. The only catch is that you have to restart Cygwin.

If you do use mkpasswd after this change, it will use your new default shell for all users that are allowed to log on.


References

1 The mkpasswd documentation says this:

Don't use this command to generate a local /etc/passwd file, unless you really need one. See the Cygwin User's Guide for more information.

I can't really find any solid reasoning in the user's guide, other than a mention that you'll have to regenerate the /etc/passwd and /etc/group files if your users and groups change, which I suppose is a decent enough reason. I can say that the process is somewhat error prone for newbies.

Tags:

Shell

Cygwin

Fish