I'm trying to change the home directory for Cygwin on a computer at work. Our home directories mapped to a network share by default. This seems to cause some confusion for Cygwin, as it created a directory on my desktop that follows the same path as the network share would, some other prefix based on where I open cygwin from.

If I open Cygwin from the default shortcut created on installation:

$ echo $HOME

If I open Cygwin from PowerShell:

$ echo $HOME

I would rather have my home directory in a local programs directory I set up for managing programs myself. Like this:


The preferred way to do this, as recommended by cygwin, is to make an entry in /etc/nsswitch.conf. This looks like it should do it:

db_home: unix /%H/Apps/cygwin/home/shaun

Any changes I have made to this file seemed to be ignored. I restart the terminal, and even when I intentionally mess up the syntax I get no errors. Some of the options I tried in and have failed:

db_home: /cygdrive/c/users/shaun/apps/cygwin/home/shaun
db_home: /%H/Apps/cygwin/home/shaun
db_home: unix /%H/Apps/cygwin/home/shaun
db_home: cygwin desc
db_home: cygwin /path /%H/Apps/cygwin/home/shaun

I restarted the Cygwin process after each attempt. I also tried changing the db_shell option to /bin/sh just as an experiment, but the shell did not change.

Past questions in StackExchange have suggested changing the /etc/passwd file, I was able to get this to work only after commenting out a block of code in /etc/profile that was automatically creating the HOME directory. And then, after some time it went back to the old HOME.

Is there something I'm missing about the /etc/nsswitch.conf file? It seems like it would be a simple and convenient way to set up custom configurations. The alternatives seem like they're outdated hacks that are not recommended by Cygwin, but if I'm wrong please let me know which method is preferred.

My current /etc/nsswitch.conf

    # /etc/nsswitch.conf
    #    This file is read once by the first process in a Cygwin process tree.
    #    To pick up changes, restart all Cygwin processes.  For a description
    #    see https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch
    # Defaults:
    # passwd:   files db
    # group:    files db
    # db_enum:  cache builtin
    # db_home:  /home/%U
    db_home: /cygdrive/c/users/shaun/apps/cygwin/home/shaun
    # db_shell: /bin/bash
    # db_gecos: <empty>
  • Please edit your question to include the complete contents of /etc/nsswitch.conf
    – DavidPostill
    Commented Jul 20, 2015 at 15:16
  • Do you have a cygwin server running? Or any cygwin processes running as wndows services? If so you need to restart all of those if you change nsswitch.conf.
    – DavidPostill
    Commented Jul 20, 2015 at 15:20
  • As per note in the docs " The /etc/nsswitch.conf file is read exactly once by the first process of a Cygwin process tree. If there was no /etc/nsswitch.conf file when this first process started, then no other process in the running Cygwin process tree will try to read the file. If you create or change /etc/nsswitch.conf, you have to restart all Cygwin processes that need to see the change. If the process you want to see the change is a child of another process, you need to restart all of that process's parents, too."
    – DavidPostill
    Commented Jul 20, 2015 at 15:20
  • @DavidPostill I've restarted the terminal and checked for any running services. Just now I restarted my machine to be sure, and there was no change to the result of the echo $HOME command in Cygwin.
    – Shaun
    Commented Jul 20, 2015 at 15:42
  • Then I'm out of ideas :/ I've never run cygwin on a networked PC using a network share for home directories. You might get a quicker answer posting on the cygwin mailing list where the developers and experts hang out. You want the first (Cygwin) mailing list mentioned on cygwin.com/lists.html " In general, you should send questions and bug reports here. This is the list for discussion of just about all things related to the Cygwin community release. If you have questions about how to use Cygwin...
    – DavidPostill
    Commented Jul 20, 2015 at 15:49

2 Answers 2


db_home: unix /%H/Apps/cygwin/home/shaun

The manual page you reference tells you to use unix or a /path, not both together.

Unless your AD administrator has set the unixHomeDirectory value for each Cygwin-using user in your organization, you do not want to use unix at all, but the path instead.

I would suggest a modification to what you've given:

db_home: /%H/Apps/cygwin/home/%u

That will allow the setting to work for multiple users on the same machine.

Any changes I have made to this file seemed to be ignored.

There are two ways to override the nsswitch.conf setting:

  1. Run Cygwin's mkpasswd utility, which generates /etc/passwd and /etc/group from either the SAM or AD user info databases. This mechanism is obsolete, and should only be used on legacy Cygwin installations or for special purposes.

  2. Set the %HOME% environment variable at the Windows system level.

    This not only overrides Cygwin, it does so only under certain circumstances, which is why it is not recommended.

    Check both the user and system-wide environment variable sets to make sure it isn't happening to you.

Past questions in StackExchange have suggested changing the /etc/passwd file

You should remove that and use your site's Active Directory system instead, with /etc/nsswitch.conf controlling how Cygwin interacts with it.


When I had trouble with a remotely-mounted home directory, I used the "map network drive" feature so My Documents got mapped to a drive letter, for instance U:\. Then U:\ becomes an alias for My Documents. Then I edited /etc/passwd so that the ~ points to /cygdrive/u and then everything worked.

This can also be done with local directories, but then the subst command has to be used in cmd.exe to create the alias instead of "Map Network Drive". Map network drive is permanent but subst is not, so a script which does it on every boot has to be placed int the Windows Start folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .