重命名/更改cygwin用户名 [英] Rename/change cygwin username
问题描述
首次启动Cygwin Shell时,您以Windows上的用户身份登录.您如何仅更改该用户的用户名,而将Cygwin用户与Windows用户之间的现有cygwin关联保留下来?(即无需创建一个新的Windows帐户)
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)
为什么?我只是从虚拟机移到Cygwin,希望重用所有脚本和shell定制,这些脚本和shell定制假定特定的用户名(例如.ssh/config,.subversion等),无需更改.
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.
推荐答案
我的原始用户名是 root
(在Windows下,具有讽刺意味的是),我希望它成为 someuser
.我想我也希望我的主目录也是/home/someuser
,并且可以从Windows读取.
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.
这就是我所做的:
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.
我创建了符号链接,以防Cygwin出于某种原因更新/etc/passwd
,并将用户名还原为 root
,并将其主目录还原为/home/root
,因此仍然可以登录.
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.
(仅用于 更改用户名: sed -e's/^ root/someuser/'-i/etc/passwd
)
(To only change the username: sed -e 's/^root/someuser/' -i /etc/passwd
)
这篇关于重命名/更改cygwin用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!