可能重复:
我如何更改我的用户名?
我正在创建一个小型 ubuntu 网络,在客户端 10.04 中,我以用户“employee1”的身份“登录”,并将我的名字更改为“Red Herring”,但我无法更改此帐户的简称。是否有终端命令或其他我需要用来执行此操作的东西?我找不到任何 GUI 方法来执行此操作。
谢谢,
德文
答案1
看man usermod
:
SYNOPSIS
usermod [options] LOGIN
-d, --home HOME_DIR
The user's new login directory.
If the -m option is given, the contents of the current home
directory will be moved to the new home directory, which is
created if it does not already exist.
-m, --move-home
Move the content of the user's home directory to the new location.
This option is only valid in combination with the -d (or --home)
option.
usermod will try to adapt the ownership of the files and to copy
the modes, ACL and extended attributes, but manual changes might
be needed afterwards.
-l, --login NEW_LOGIN
The name of the user will be changed from LOGIN to NEW_LOGIN.
Nothing else is changed. In particular, the user's home directory
name should probably be changed manually to reflect the new login
name.
所以你要
sudo usermod -m -d /home/new_login_name old_login_name
sudo usermod -l new_login_name old_login_name
第一个命令将移动您的登录目录;第二个命令将编辑引用您名称的相关文件(/etc/passwd
、/etc/shadow
、/etc/groups
)old_login_name
到new_login_name
。您没有要求,但您可能还想以groupmod
类似的方式更改您的组名(sudo groupmod -n new_group_name old_group_name
)。