When you first start the Cygwin shell, you are logged in as the user you are on Windows. How do you change just the username of that user, leaving the existing cygwin association of the Cygwin user with the Windows user? (i.e. without creating a whole new Windows account)
Why? I just moved over from a virtual machine to Cygwin and wish to reuse all my scripts and shell customizations which assume a specific username (think of .ssh/config, .subversion, etc.) without change.
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.
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)
This is what worked for me (Windows 10):
rm /etc/passwdmkpasswd -c > /etc/passwdln -s /home/oldname /home/newnamesed -i 's/oldname/newname/g' /etc/passwdIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With