January 12, 2015

How can I change my Cygwin home folder after installation?

Firstly, set a Windows environment variable for HOME that points to your user profile:

  1. Go to Control Panel --> System and Security --> System (or press the [WINDOWS]+PAUSE|BREAK] keys)
  2. Click Advanced system settings (located at the left)
  3. Click Environment Variables (toward the bottom)
  4. In the User Variables area click "New…"
  5. For Variable name enter HOME
  6. For Variable value enter %USERPROFILE%
  7. Click OK in all the open dialog boxes to apply this new setting

Now we are going to update the Cygwin /etc/passwd file with the Windows %HOME% variable we just created. Shell logins and remote logins via ssh will rely on /etc/passwd to tell them the location of the user's $HOME path.

At the Cygwin bash command prompt type the following:

cp /etc/passwd /etc/passwd.bak
mkpasswd -l -p $(cygpath -H)  > /etc/passwd
mkpasswd -d -p $(cygpath -H)  >> /etc/passwd

The -d switch tells mkpasswd to include DOMAIN users as well as LOCAL machine users. This is important if you're using a PC at work where the user information is obtained from a Windows Domain Controller.

Now, do the same for groups by executing the following:

cp /etc/group /etc/group.bak
mkgroup -l > /etc/group
mkgroup -d >> /etc/group

Now, exit Cygwin and start it up again. You should find that your HOME path points to the same location as your Windows User Profile -- i.e. /cygdrive/c/Users/username

©