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
/cygdrive/c/Users/shaun/Desktop/SERVER/USERS:USERS/SHAUN
If I open Cygwin from PowerShell:
$ echo $HOME
/usr/bin/SERVER/USERS:USERS/SHAUN
I would rather have my home directory in a local programs directory I set up for managing programs myself. Like this:
/cygdrive/c/users/shaun/apps/cygwin/home/shaun
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>
/etc/nsswitch.conf– DavidPostill Jul 20 '15 at 15:16If 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 Jul 20 '15 at 15:20echo $HOMEcommand in Cygwin. – Shaun Jul 20 '15 at 15:42