Changing Cygwin Username and $HOME Directory

On first installing Cygwin, the username is inherited from Windows, and the $HOME directory is created from this username. This is particularly annoying if Windows was originally set up with a multi-word username such as “Firstname Lastname”. This quick guide will show how to change the username and $HOME directory to something more simple.

Creating New $HOME Directory, and /etc/passwd File

After installing Cygwin (obviously downloaded from here), you’ll be greeted by the following screen:

All I’ve done is created a new “dev” home directory:

cd ..
mkdir dev

Then created the passwd file:

mkpasswd /etc/passwd

The /etc/passwd file stores user account information required by the shell at login.

Altering the New /etc/passwd File

Editing the new /etc/passwd File using vi:

vi /etc/passwd

Will give us something similar to the following:

The text is colon-separated as follows:

USERNAME:PASSWORD:USER_ID:GROUP_ID:USER_ID_INFO:HOME_DIRECTORY:SHELL

Or bulleted for easier viewing:

  1. Username
  2. Password
  3. User ID (UID)
  4. Group ID (GID)
  5. User ID Info
  6. Home Directory
  7. Shell

The two highlighted keys are the Username (the first key) and $HOME Directory (the sixth key) respectively, in my install, I’ve simply changed these to “dev” for the Username, and “/home/dev” for the new $HOME Directory.

To test these, simply close and re-open Cygwin, you’ll be greeted with the following screen:

That’s all there is to it.

References

  • More on /etc/passwd

http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/

Leave a Comment

Your email address will not be published. Required fields are marked *