Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename/change cygwin username

Tags:

cygwin

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.

like image 896
Irfy Avatar asked Oct 27 '13 01:10

Irfy


3 Answers

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.

like image 131
phk Avatar answered Oct 15 '22 03:10

phk


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)

like image 23
Irfy Avatar answered Oct 15 '22 04:10

Irfy


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
like image 5
birgersp Avatar answered Oct 15 '22 05:10

birgersp