23

As I am developing Ruby on Rails on a Windows machine, I need to use cygwin to emulate the Unix command prompt. The problem now is that every time when I open the cygwin terminal, I am brought to this directory C:/cygwin/home/my_user_name instead of the Windows' default user directory C:/Users/my_user_name.

Does anyone know how to make cygwin's default home directory to Windows default C:/Users/my_user_name directory?

I have skimmed through the various solutions provide in Stack Overflow, but none of them works for me, the "mkpasswd" doesn't work either. Does this have something to do with my operating system's version, or maybe something else?

I am using cygwin 1.7.5 and my operating system is Windows 7 Business 64 bit.

Kyle Strand
  • 15,941
  • 8
  • 72
  • 167
lixiang
  • 1,941
  • 3
  • 20
  • 25

3 Answers3

22
mount -f "$USERPROFILE" ~
mount -m > /etc/fstab

Related

Safely change home directory

Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407
13

According to Cygwin documentation you can edit /etc/nsswitch.conf and change de db_home parameter.

  • %u - The Cygwin username (that's lowercase u).
  • %U - The Windows username (that's uppercase U).
  • %D - Windows domain in NetBIOS style.
  • %H - Windows home directory in POSIX style. Note that, for the db_home: setting,
  • %_ - Since space and TAB characters are used to separate the schemata, a space in the filename has to be given as %_ (that's an underscore).
  • %% - A per-cent character.

Here is the content of my /etc/nsswitch.conf to create a home directory into each user directory

# /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 <------ This was the default setting
db_home: /%H/home # db_home: /home/%U <- This was the default setting
# db_shell: /bin/bash
# db_gecos: <empty>

Restart any Cygwin process

Guish
  • 4,968
  • 1
  • 37
  • 39
  • 2
    Note that this will be overridden if `HOME` is set (as Hut8 suggests). I prefer this solution in general, but I have found a [strange case where something *else* seems to override it](http://stackoverflow.com/q/41152489/1858225), so I've switched to the solution of setting the Windows environment variable. – Kyle Strand Dec 15 '16 at 04:43
  • 1
    This seems to be a cleaner solution, should be accepted instead ! – Phizaz May 21 '17 at 07:33
  • Great! I changed `db_home` to `/%H`, that is exactly my Windows home directory. – Daliang LYU Sep 25 '22 at 07:58
10

I was able to change mine by simply setting the HOME environment variable in Windows to C:\Users\MyUsername. When I start Cygwin, now it looks there. This has the added benefit of causing Emacs on regular Win32 (i.e., not via Cygwin) to start in the right place instead of in C:\Users\MyUsername\AppData\Roaming (and thus looking for .emacs and .emacs.d there)

Hut8
  • 6,080
  • 4
  • 42
  • 59
  • When I do that, Cygwin gives me back this: mkdir: cannot create directory `/cygdrive/c/ProgramData/Microsoft/Windows/Start Menu/Programs/Cygwin/\'C:': Permission denied /cygdrive/c/ProgramData/Microsoft/Windows/Start Menu/Programs/Cygwin/'C:/Users/CMCDragonkai' could not be created. Setting HOME to /tmp. – CMCDragonkai Apr 30 '14 at 08:05
  • Don't forget to logout/login for this environment variable to take effect. – Apteryx Jul 07 '17 at 21:20
  • Notably `ssh-keygen` wants to put its keys in `/home/` even with HOME is set via Windows env vars. – Michael Campbell Dec 03 '22 at 20:54