Rename/change cygwin username

This is what worked for me (Windows 10):

  1. rm /etc/passwd
  2. mkpasswd -c > /etc/passwd
  3. ln -s /home/oldname /home/newname
  4. sed -i 's/oldname/newname/g' /etc/passwd

This is what I did that worked on Windows 10 which combines elements of three other answers:

  1. Verify your Cygwin /etc/passwd does not exist
  2. cd /home
  3. mv oldname newname
  4. ln -s newname oldname
  5. "mkpasswd -l > /etc/passwd" (this will insert many accounts into your new /etc/passwd)
  6. sed -i 's/oldname/newname/g' /etc/passwd
  7. kill all cygwin shells
  8. bring up a new cygwin shell

My original username was root (under Windows, ironically), and I wanted it to be someuser. I figured I'd want my home dir to be /home/someuser as well, and be readable from Windows.

This is what I did:

cd /home
mv root someuser
ln -s someuser root
sed -e 's/^root/someuser/' -e 's/\/home\/root/\/home\/user/' -i /etc/passwd

And that's all, just restart the shell.

I made the symlink in case Cygwin updates /etc/passwd for some reason, and restores the username to root and its home dir to /home/root, so that it is still possible to log in.

(To only change the username: sed -e 's/^root/someuser/' -i /etc/passwd)


For people starting with a clean Cygwin installation an approach might be to create new /etc/passwd file (it does not exist per default in current Cygwin versions) using mkpasswd -l >/etc/passwd which will create an entry for every user (add -b to omit the built-in users or just -c to only create an entry for the current user, see https://cygwin.com/cygwin-ug-net/mkpasswd.html).

Next, simply open /etc/passwd rename the account in there (first column).

See https://cygwin.com/cygwin-ug-net/ntsec.html for a description of how Cygwin handles the mapping between "Cygwin" and Windows user. Oh and there is also a mkgroup that can be used similarly, see https://cygwin.com/cygwin-ug-net/mkgroup.html.

You will see that creating is not officially recommended but from my experience it has not caused any problems, maybe it could if you would do quite advanced stuff involving user/group rights or if you didn't keep it up-to-date when you change the Windows users.

Tags:

Cygwin